Cooper94 Posted December 6, 2009 Share Posted December 6, 2009 Is it possible to have a script check every minute to make sure the user is still online? <?php $inactive = 60; if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive) { mysql_query("UPDATE pilots SET online = '0' WHERE callsign = '$_SESSION[username]'"); }} $_SESSION['timeout'] = time(); mysql_query("UPDATE pilots SET online = '1' WHERE callsign = '$_SESSION[username]'"); ?> This does the tick but the client needs to refresh the page to online = 0. Is it possible to have it go to 0 before they refresh? So that when they do refresh the page from being back it will than upate the status to online = 1? Thank you for your time and all your help! Link to comment https://forums.phpfreaks.com/topic/184198-sessions-online-users/ Share on other sites More sharing options...
greatstar00 Posted December 6, 2009 Share Posted December 6, 2009 u can combine your mysql session, and cron job but your need to change your code a bit Link to comment https://forums.phpfreaks.com/topic/184198-sessions-online-users/#findComment-972464 Share on other sites More sharing options...
Cooper94 Posted December 6, 2009 Author Share Posted December 6, 2009 Is there any way you can help me out? Thank You Link to comment https://forums.phpfreaks.com/topic/184198-sessions-online-users/#findComment-972489 Share on other sites More sharing options...
greatstar00 Posted December 6, 2009 Share Posted December 6, 2009 does your server support cron job? Link to comment https://forums.phpfreaks.com/topic/184198-sessions-online-users/#findComment-972491 Share on other sites More sharing options...
Cooper94 Posted December 6, 2009 Author Share Posted December 6, 2009 Yes, sir Link to comment https://forums.phpfreaks.com/topic/184198-sessions-online-users/#findComment-972513 Share on other sites More sharing options...
Cooper94 Posted December 9, 2009 Author Share Posted December 9, 2009 I know this is old but I did setup a cron job for a script that runs and checks to see if the user has reached its limit but it does not work. But if I go to the url the script is located on it will update the database no problem! Below is my script: <?php include '../includes/db.php'; session_start(); $inactive = 60; if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive) { mysql_query("UPDATE pilots SET online = '0' WHERE callsign = '$_SESSION[username]'"); }} ?> The $_SESSION['timeout'] is a vairable that that equavilant to time() which is set when the person refreshs any page on the site, I have tested that in an echo and it is outputing a number. Like I said it does work when I go to the script location in my browser. Any help would be great! Thank You Link to comment https://forums.phpfreaks.com/topic/184198-sessions-online-users/#findComment-973866 Share on other sites More sharing options...
Cooper94 Posted December 9, 2009 Author Share Posted December 9, 2009 *bump* Link to comment https://forums.phpfreaks.com/topic/184198-sessions-online-users/#findComment-973883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.