Jump to content

detecting who is online?


astralaaron

Recommended Posts

If all users shall be logged in, you could update your table with users when a user logs in/out. Like when he/she/it logs in:$username = $_POST['username'];UPDATE users SET status ='Online' WHERE username = '$username'And then to count how many that's logged in:$rsa = mysql_query("SELECT status FROM users WHERE status = 'online'");echo mysql_num_rows($rsa);

Link to comment
Share on other sites

If all users shall be logged in, you could update your table with users when a user logs in/out. Like when he/she/it logs in:$username = $_POST['username'];UPDATE users SET status ='Online' WHERE username = '$username'And then to count how many that's logged in:$rsa = mysql_query("SELECT status FROM users WHERE status = 'online'");echo mysql_num_rows($rsa);
Just curious, how would you update who logs off? Because maybe the user would just close their browser, so you couldn't initiate any code on a page they close... Is there some way you can periodically check to see if the user corresponding to those logged in are still online? Or something?
Link to comment
Share on other sites

Just curious, how would you update who logs off? Because maybe the user would just close their browser, so you couldn't initiate any code on a page they close... Is there some way you can periodically check to see if the user corresponding to those logged in are still online? Or something?
I would suggest updating some record in the users table which indicates the last time a page was requested by them. Then, if you have some pre-defined session time limit, like 15 minutes or so, you could compare the time that is stored in that table with the current time. If the difference is greater than your limit (e.g. 15 minutes) then you can safely assume that the user is logged out.
Link to comment
Share on other sites

I would suggest updating some record in the users table which indicates the last time a page was requested by them. Then, if you have some pre-defined session time limit, like 15 minutes or so, you could compare the time that is stored in that table with the current time. If the difference is greater than your limit (e.g. 15 minutes) then you can safely assume that the user is logged out.
Is that probably what most websites who display who's online do? Because, if I recall correctly, I always get really upset when people log off of MySpace or something and it still shows them as online, so I comment them, then minutes later it shows them as logged off and they didn't respond to a comment I left them. =P Sounds accurate to me though.Thanks.
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...