Session counting

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hello all,

There is system. Users are logging , working and logout.
Suppose, 5 users are working and Admin wants to find out no. of users
working on system with their name ?

How to find this ?

Thanks in advance.

Re: Session counting

pradeep wrote:

Quoted text here. Click to load it

Depends. Are you on a shared server? Are you using PHP's standard sessions?

If yes to both, then the answer is no! (Well, it could be done, but not  

Best option is to write your own session handler -- i.e. the piece of code  
which deals with saving and restoring session data -- easier than it  
sounds! Store the session data in a database, and then you can simply use  
a SQL COUNT(*) query to find the number of open sessions.


The comment from maria at junkies dot jp, dated 09/12/07 is a reasonably  
good starting point.

Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux, up 10 days, 21:16.]

                      Sharing Music with Apple iTunes

Re: Session counting

pradeep wrote:
Quoted text here. Click to load it

In addition to what Toby said, you can do it even on a shared host, but  
neither is reliable.  They work fine if the user logs off, but not if he  
just shuts down his browser.

To do it without your own session handler, you need to keep a list of  
logged-in people.  Probably a flag in the database would be most  

But you'll also need a timestamp field to tell when they did log in, and  
if they've been logged in longer than the session time limit, you need  
to clear the flag.  Maybe easier would be just a timestamp - if it  
exists, the person is logged in.  When the person logs out, clear the  

Then you need a program (i.e. a cron job) to go through the list on a  
regular basis to clear users who have been logged in to long.

But none of this is very accurate.  They really only tell you who logged  
on - not whether they were still active.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline