Jump to content

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]

^_^
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.