Page 1 of 1

users online

Posted: Sun Oct 22, 2006 11:08 pm
by speedy33417
I have a password protected website with PHP sessions. How do I show how many people are logged in at the moment?

I have the users last logged in time saved in a database. I could even create a new field for last page visit and update that each time the user visits the next page. First I was thinking showing users as online if their last page visit is no older than five minutes. However that user could log out a second after his/her last page visit, or stay logged in but not refresh or move from a page for hours...

How can it be done?

Posted: Sun Oct 22, 2006 11:43 pm
by Burrito

Re: users online

Posted: Mon Oct 23, 2006 3:42 am
by s.dot
speedy33417 wrote:I could even create a new field for last page visit and update that each time the user visits the next page.
That's how it's done. :-D
speedy33417 wrote:First I was thinking showing users as online if their last page visit is no older than five minutes. However that user could log out a second after his/her last page visit, or stay logged in but not refresh or move from a page for hours...
You'll just have to live with them logging out before 5 minutes is up. 5 minutes is still an accurate representation of who is online. This forum determines who is online by using a 5 minute timeout.

As far as the hours thing, if your script checks whos been active in the last 5 minutes, then it doesn't matter if someone idles.. they will be shown as logged out.

If you want a truly accurate representation (including when they logout, and who is idle but still online), then you could have a transparent image, or even a hidden frame that sends a query to update their timestamp in the db every X seconds.

The latter method is not preferred due to excessive amounts of queries being sent.

Posted: Mon Oct 23, 2006 7:56 am
by speedy33417
Thank you both for your input. I'll look into Ajax and for the time being I'll use the 5 minute timeout.