Page 1 of 1
Display logged in members
Posted: Sun Mar 27, 2005 1:16 am
by Jim_Bo
Hi,
Whats the best way to echo (display the user names) an accurate reading of the user names that are logged in?
Thanks
Posted: Sun Mar 27, 2005 1:43 am
by feyd
search: who's online.
Posted: Sun Mar 27, 2005 2:52 am
by Jim_Bo
Hey,
This code below .. below suits my user database .. It seems to echo all users rather than only users that have been active for less that 5 minutes?
Code: Select all
$time = time();
$timeonline = '300';
$timedifference = time() - $timeonline;
$whosonline = mysql_query("SELECT * FROM users WHERE last_login >= '$timedifference'");
while($whosonlinearray = mysql_fetch_array($whosonline)){
echo $whosonlinearray['alias'];
}
Thanks
Posted: Sun Mar 27, 2005 7:09 am
by anjanesh
Whats the type of last_login ? Date, Time, Integer, Varchar ?
If its any of the date/time types then this should work :
$whosonline = mysql_query("SELECT * FROM users WHERE UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(last_login) <=500");
Posted: Sun Mar 27, 2005 4:04 pm
by Jim_Bo
Hi,
Im using now() to insert with date/time as setting .. Your code works great thanks ..
Another question with sessions .. When people logout things work fine .. but when they just close the browser the session stays active for like 5 minutes .. giving false readings of whos online etc etc .. Can anything be done so when the browser is closed .. the session is destroyed at the same time? How are things done witihn the likes of devnetworks forum etc .. or is the session timout the best answer ..?
Cheers
Posted: Sun Mar 27, 2005 7:07 pm
by feyd
the timeout is what kills the session if they don't log out. It works just fine.. There's almost no way to know definitively who is looking at a particular page from second to second, because that request is the only live connection you will typically have. Unless you are using a realtime media connection, there is little way to know all the time.
These things are a basic snapshot of who has been active in the last x minutes, nothing more.
Posted: Sun Mar 27, 2005 7:31 pm
by Jim_Bo
Hey,
Great .. Thanks for that explaination ..