djfox Posted January 7, 2008 Share Posted January 7, 2008 I have it where when the user logs in, their status switches to online, and when they click the logout link, their status changes to logout. But how does this get changed when they just close the browser? Quote Link to comment https://forums.phpfreaks.com/topic/84933-solved-offlineonline-status-help/ Share on other sites More sharing options...
revraz Posted January 7, 2008 Share Posted January 7, 2008 Set a time stamp and if it hasnt been updated say for 5 mins, they are offline. Quote Link to comment https://forums.phpfreaks.com/topic/84933-solved-offlineonline-status-help/#findComment-433038 Share on other sites More sharing options...
djfox Posted January 7, 2008 Author Share Posted January 7, 2008 Hm, ok. How would I do this exactly? Quote Link to comment https://forums.phpfreaks.com/topic/84933-solved-offlineonline-status-help/#findComment-433044 Share on other sites More sharing options...
GingerRobot Posted January 7, 2008 Share Posted January 7, 2008 Its a common misconception. You shouldn't be storing an online/offline status, because, as you've noticed, you run into issues if someone closes the browser. What you should be doing is storing a 'last active' timestamp. This will, of course, need to be updated on each page. When working out who is online, you'll select only those users who were last active in, say, the last 300 seconds (5 minutes). Quote Link to comment https://forums.phpfreaks.com/topic/84933-solved-offlineonline-status-help/#findComment-433054 Share on other sites More sharing options...
rempires Posted January 7, 2008 Share Posted January 7, 2008 put the time stamp into your mysql table, when they log in update the time. You can then use that time to check and see if he is still logged in. Whenever he visits a new page update the time in the db with the new time. If that time stamp has not been updated for 5min safe to say he's offline usually and if not when he visits a new page it will update that time stamp and put him back online. Quote Link to comment https://forums.phpfreaks.com/topic/84933-solved-offlineonline-status-help/#findComment-433056 Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 I have it where when the user logs in, their status switches to online, and when they click the logout link, their status changes to logout. But how does this get changed when they just close the browser? If you're asking HOW it gets changed when the person closes their browser, the answer is sessions. Quote Link to comment https://forums.phpfreaks.com/topic/84933-solved-offlineonline-status-help/#findComment-433061 Share on other sites More sharing options...
djfox Posted January 7, 2008 Author Share Posted January 7, 2008 The recommended way to handle this is that when the person visits a page, their time slot in the database gets updated? Ok, I have one other question in regards to that. This the method of recording time/date in the database I use for my site: strftime("%B\ %e\,\ %Y %H:%M:%S", time()) How do I check the time to see if they get counted as online? Quote Link to comment https://forums.phpfreaks.com/topic/84933-solved-offlineonline-status-help/#findComment-433062 Share on other sites More sharing options...
kratsg Posted January 8, 2008 Share Posted January 8, 2008 I have it where when the user logs in, their status switches to online, and when they click the logout link, their status changes to logout. But how does this get changed when they just close the browser? If you're asking HOW it gets changed when the person closes their browser, the answer is sessions. That makes no sense, honestly. A PHP script cannot determine when a session has ended, unless it checks (but then that means the person's online and defeats the purpose) The recommended way to handle this is that when the person visits a page, their time slot in the database gets updated? Ok, I have one other question in regards to that. This the method of recording time/date in the database I use for my site: strftime("%B\ %e\,\ %Y %H:%M:%S", time()) How do I check the time to see if they get counted as online? Here's how I would do it, personally. Timestamps, use the time() alone and store that as an int string in the database. So.. I visit a page, the following code runs: <?php @mysql_query("UPDATE `users` SET `last_active` = ".time()." WHERE `username` = $user LIMIT 1") or die(mysql_error()); ?> This just basically gets the current timestamp and sets it in the database... Then checking all users to see who is online... <?php $inactivity = 300;//300 seconds = 5 minutes $inactive_time = time() - $inactivity;//all users active since this time ago are considered still active $query = "SELECT username FROM `users` WHERE `last_active` >= $inactive_time ORDER BY `last_active` DESC"; while($row = mysql_fetch_array(mysql_query($query) or die(mysql_error()))){ echo $row['username']."<br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84933-solved-offlineonline-status-help/#findComment-433149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.