Jump to content

Members online - checking for exit?


markspec87

Recommended Posts

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

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 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

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.