johnsmith153 Posted June 10, 2010 Share Posted June 10, 2010 I want to display number of users actually logged in at the moment. How would be the best way to do this? Would you add a record to a dbase when they log in, then delete when they log out (then count records in that table to get the current loggd in number)? If you did this what if they just closed the browser without logging out on the server? Link to comment https://forums.phpfreaks.com/topic/204356-displaying-logged-in-users/ Share on other sites More sharing options...
N-Bomb(Nerd) Posted June 10, 2010 Share Posted June 10, 2010 It sounds to me like you're on the right path. I'm a bit curious about this as well, however the only flaw I see with your idea is what if the user never logs out? I think it might be more suitable if you was to run a cronjob every x minutes (15 is good) and check to see if the session still exists and if not remove from the user from active list in the database. Link to comment https://forums.phpfreaks.com/topic/204356-displaying-logged-in-users/#findComment-1070211 Share on other sites More sharing options...
Andy-H Posted June 10, 2010 Share Posted June 10, 2010 //validate user login $activity = time() + 300; //5 mins $query = "UPDATE users SET logged_in = $activity WHERE name = '" . mysql_real_escape_string($_POST['username']) . "' LIMIT 1"; $result = mysql_query($query); //update user timestamp to time() + 300 on each page request. usersonline $now = time(); $query = "SELECT name FROM users WHERE logged_in >= $now ORDER BY id DESC"; $result = mysql_query($query); while ($row = mysql_fetch_row($result)) echo $result[0] . ', '; echo 'currently active: ' . mysql_num_rows($result); Link to comment https://forums.phpfreaks.com/topic/204356-displaying-logged-in-users/#findComment-1070214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.