Jump to content

Sessions: Detect online status of members? Ideas?


cronoklee

Recommended Posts

I have a simple membership system on my site using PHP & mySQL. I track users with sessions using session_start() at the top of every page.
I was wondering if anyone knows how I could detect members online status? I'd like to have a note beside each username, saying if they are online now or not.

Thanks a lot,
Ciaran
one way that i used to do this is by updating a database with the last action of each user (essentially the last time the user requested a page). on every page i updated a table with the user's id, and the current datetime. when echoing how many users were online (or, in your case, whether or not a user is online) i simply grabbed the users that had requested a page in the last 5 minutes.

a few notes about this. first of all, if you've got a lot of users likely to be on at the same time, as well as a lot of page hits, i'm pretty sure you're going to choke the hell out of your database. second, someone else may have a better idea for this - this is just a home-brewed method. i never knew whether the server itself had a list of current session connections or cookies. if it does, you may want to consult that instead, as it gives you a direct link to who is and isn't currently online.
I would agree with akitchin's method. If you wanted to reduce the load on your database you could have it updated once they log in and keep a session variable of it. Then each page could check whether there was a time difference greater than 5 minutes between the current time and the session time and if so, update the session and the database again, then in your script to check if people are logged in, it would pull every value from the database and check if there was a time difference greater than 5 minutes and if so, do not show the user as online. This isn't as accurate but you could adjust the accuracy by fiddling with the times
[!--quoteo(post=381686:date=Jun 8 2006, 08:53 PM:name=akitchin)--][div class=\'quotetop\']QUOTE(akitchin @ Jun 8 2006, 08:53 PM) [snapback]381686[/snapback][/div][div class=\'quotemain\'][!--quotec--]
dynamite solution to the database lagging. thanks Fyorl.
[/quote]

^_^

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.