Swarfega Posted January 4, 2013 Share Posted January 4, 2013 (edited) Hey. I've made a script that would auto-logout users have they not been active for 15min, but it seems to not be working properly.. I've included these two files in ALL my php's that display data, so that each and every single user contributes to the Currently-Online-Members script whenever they click one of the links. update_timer.php <?php session_start(); require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $getdate = date('H:i:s'); $SQL = "UPDATE potatis SET last_activity='".$getdate."' WHERE uid='".$_SESSION['SESS_MEMBER_ID']."'"; mysql_query($SQL) or die(mysql_error()); ?> logout_timer.php <?php require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $getdate = date("H:i:s"); $date = explode(":", $getdate); $date[0] = $date[0] * 60 * 60; $date[1] = $date[1] * 60; $totalsecondsnow = $date[0] + $date[1] + $date[2]; $SQL = "SELECT uid, last_activity FROM potatis"; $RESULT = mysql_query($SQL); while($row = mysql_fetch_assoc($RESULT)) { $thendate = explode(":", $row['last_activity']); $thendate[0] = $thendate[0] * 60 * 60; $thendate[1] = $thendate[1] * 60; $totalsecondsthen = $thendate[0] + $thendate[1] + $thendate[2]; $totalsecondsallowed = $totalsecondsthen + 900; if($totalsecondsnow > $totalsecondsthen) { $qry = "UPDATE potatis SET connected='offline' WHERE uid='". $row['uid'] . "'"; mysql_query($qry) or die(mysql_error()); } else { $qry = "UPDATE potatis SET connected='online' WHERE uid='". $row['uid'] . "'"; mysql_query($qry) or die(mysql_error()); } } ?> But it does not seem to work properly.. One person signed on at 13:53 my time, the time when I checked the database, her last_activity was 13:53:43 or something, and the current time was 13:55:23, yet it still showed her being offline, is that not just very wrong? Where did I go wrong in the script to make that happen? Edit: It does however not put MY user as Offline when I click on a link, my last_activity was 14:01 Edited January 4, 2013 by Swarfega Quote Link to comment https://forums.phpfreaks.com/topic/272692-15min-expiration-logout-script/ Share on other sites More sharing options...
MDCode Posted January 4, 2013 Share Posted January 4, 2013 (edited) if($totalsecondsnow > $totalsecondsthen) { Shouldn't that be... if($totalsecondsnow > $totalsecondsallowed) { The way you have it now is like saying, if the current time is greater than their last activity, log them off. Although I'm not even sure the way above will still work Edited January 4, 2013 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/272692-15min-expiration-logout-script/#findComment-1403182 Share on other sites More sharing options...
Swarfega Posted January 4, 2013 Author Share Posted January 4, 2013 Wow, can't believe i missed that... But yeah it seems to be working properly now, hope it stays that way.. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/272692-15min-expiration-logout-script/#findComment-1403184 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.