markspec87 Posted December 21, 2006 Share Posted December 21, 2006 Im trying to implement a script that will check if a member is online and then display "members online: 3"When they login it updates their "online" field to 1, and my index just outputs how many rows have their online set to 1.My question is when a user logs out (by closing the browser, how can i detect this and set online to 0?)If they use my logout script it sets it to 0, but other than that i dont know how i can account for a user closing the browser?Maybe im going about this the wrong way?Hopefully you can help me :) Link to comment https://forums.phpfreaks.com/topic/31440-members-online-checking-for-exit/ Share on other sites More sharing options...
michaellunsford Posted December 21, 2006 Share Posted December 21, 2006 Instead of using a 1 or 0, make it a timeout field. If the user is inactive for, say, two minutes, they don't show up anymore.[code=php:0]mysql_query("SELECT * FROM `users` WHERE `online` >= '".(time()-(60*2))."'");[/code] Link to comment https://forums.phpfreaks.com/topic/31440-members-online-checking-for-exit/#findComment-145606 Share on other sites More sharing options...
Nhoj Posted December 21, 2006 Share Posted December 21, 2006 [quote author=michaellunsford link=topic=119468.msg489352#msg489352 date=1166669190]Instead of using a 1 or 0, make it a timeout field. If the user is inactive for, say, two minutes, they don't show up anymore.[code=php:0]mysql_query("SELECT * FROM `users` WHERE `online` >= '".(time()-(60*2))."'");[/code][/quote]I do the same thing on my website, however, at the top of each page you'll need something like...[code=php:0]mysql_query('UPDATE `users` SET `online` = UNIX_TIMESTAMP() WHERE `uID` = '.$uID.' LIMIT 1');[/code]Otherwise the value will never change Link to comment https://forums.phpfreaks.com/topic/31440-members-online-checking-for-exit/#findComment-145621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.