Seaholme Posted July 20, 2010 Share Posted July 20, 2010 Hey, I'm trying to create a page which will list all the users currently online, but all I can find via google are scripts to say how many are online, not who they are. I thought I would do it so that, when people log in, their 'online/offline' column in the database is changed from 0 to 1. However, I don't know how to make it so that when the session times out, this column will revert back to 0. Can anybody help me work out how I might be able to do this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/208292-getting-a-php-script-to-run-when-a-session-times-out/ Share on other sites More sharing options...
Wolphie Posted July 20, 2010 Share Posted July 20, 2010 I'm not sure if this would be the best way to do it, however you could add a time column in the users table. When a user logs on, or visits a page (all pages) update the table with the current time. If that time is older than 5 minutes (or what ever you choose) then set the value to 0. You could improve the process a little bit more by adding a script inside crontab to run every 5 minutes to check the times. Like above, if the time is 5 minutes in the past, then set the value to 0. Quote Link to comment https://forums.phpfreaks.com/topic/208292-getting-a-php-script-to-run-when-a-session-times-out/#findComment-1088599 Share on other sites More sharing options...
JonnoTheDev Posted July 20, 2010 Share Posted July 20, 2010 Yes, record the expiry time and the last click time in a database. Every click both values should increment. If the expiry time is passed the current time, then the user is obviously inactive. Have a look through the following tutorials. You'll get the idea. http://www.tutcity.com/tutorial/php-user-online.21756.html Quote Link to comment https://forums.phpfreaks.com/topic/208292-getting-a-php-script-to-run-when-a-session-times-out/#findComment-1088600 Share on other sites More sharing options...
Seaholme Posted July 20, 2010 Author Share Posted July 20, 2010 Thanks guys! I decided to do what you suggested and I have a lastclick column in the database now... I'd really like to be able to write a script which would check if the lastclick was within the last 5 minutes (or actually just anything which will calculate how long it was since the last click). This is the script I'm trying to use to work out what the time difference is, but it persists in showing the difference as = 8 no matter what! Can anybody help me sort it out? // Find highest answer number. $sql = "SELECT * FROM players"; $result2=mysql_query($sql) or die(mysql_error()); while ($rows=mysql_fetch_array($result2)){ echo $rows['lastclick']; } $currentdate=date("G:i:s d/m/y"); $difference = $currentdate - $rows['lastclick']; echo $difference; Quote Link to comment https://forums.phpfreaks.com/topic/208292-getting-a-php-script-to-run-when-a-session-times-out/#findComment-1088613 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.