cronoklee Posted June 9, 2006 Share Posted June 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11545-sessions-detect-online-status-of-members-ideas/ Share on other sites More sharing options...
akitchin Posted June 9, 2006 Share Posted June 9, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11545-sessions-detect-online-status-of-members-ideas/#findComment-43465 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11545-sessions-detect-online-status-of-members-ideas/#findComment-43470 Share on other sites More sharing options...
akitchin Posted June 9, 2006 Share Posted June 9, 2006 dynamite solution to the database lagging. thanks Fyorl. Quote Link to comment https://forums.phpfreaks.com/topic/11545-sessions-detect-online-status-of-members-ideas/#findComment-43476 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 [!--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]^_^ Quote Link to comment https://forums.phpfreaks.com/topic/11545-sessions-detect-online-status-of-members-ideas/#findComment-43479 Share on other sites More sharing options...
cronoklee Posted June 14, 2006 Author Share Posted June 14, 2006 Great - I'll try it out. Thanks a lot ;) Quote Link to comment https://forums.phpfreaks.com/topic/11545-sessions-detect-online-status-of-members-ideas/#findComment-45704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.