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
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Users online

Post by Ree »

To be able to display currently active users (say, in a forum) you need to set that activity in the db somehow. If some user leaves the forum (closes his browser, for example), how would you know he had became inactive? You won't be able to update db, because you won't know he actually left at that moment. The solution I could think of is simply logging user's clicks and saving timestamps in the db, and then when you need to check active users, you compare current timestamp with the latest one of each user - if the difference is larger than some time interval, the user is considered inactive, otherwise he's considered active. Is that how you do it, or is there a better way? How does phpBB do this?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

phpBB and other "who's online solutions" store sessions information in a db. Included in that info is the date of last page request. You just execute a query of who's online within a give period of time usually 10-15 minutes.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

For more fine grained access you can program AJAX to cause users to phone into the server while their server is still on. At the extreme end you implement a fat-client that *must* phone back to the server.

But neophyte's solution is the most commonly deployed.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

AJAX solutions are usually more accurate, with 'traditional' users online systems working off unique IPs (to determine guests, not registered users) a google bot crawl can trick your system into thinking there is 100's of extra users on the system since the bots come from multiple IPs, I've had it happen to me a few times.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Post Reply