users online

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

users online

Post 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?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: users online

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post 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.
Post Reply