JoelRocks Posted August 24, 2007 Share Posted August 24, 2007 Wondered the function that i would use to compare time, i am going to get the time at session start and then compare it with the time at the end of the session, if that is over 30 minutes then the session is ended. What you recon? breaking the time down into year/month/day/minute/hours/seconds and save the infomation into the database... what you guys recon? Link to comment https://forums.phpfreaks.com/topic/66549-php-comparing-time-for-custom-session-timeouts/ Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 This is really old, but it worked when I made it. This you do when you set the session. $temp = getdate(); $_SESSION['timestampmday'] = $temp['mday']; $_SESSION['timestamphours'] = $temp['hours']; $_SESSION['timestampminutes'] = $temp['minutes']; $_SESSION['user'] = $_POST['user']; Then check it for timing out with this: function testTime() { $newtime = getdate(); if ($newtime['mday'] != $_SESSION['timestampmday']) session_destroy(); if ($_SESSION['timestampminutes'] <= 49) { if ($newtime['hours'] != $_SESSION['timestamphours']) session_destroy(); if ($newtime['minutes'] >= ($_SESSION['timestampminutes']+10)) session_destroy(); } else { $newtest = (60-$_SESSION['timestampminutes']); if ($newtime['minutes'] <= 10) { if (($newtime['minutes']+$newtest) >= 10) session_destroy(); } else { if ($newtime['hours'] != $_SESSION['timestamphours']) session_destroy(); } } } I think if they keep the browser open for one day and start clicking again at the exact same hour it started it will still let them in. Link to comment https://forums.phpfreaks.com/topic/66549-php-comparing-time-for-custom-session-timeouts/#findComment-333328 Share on other sites More sharing options...
GingerRobot Posted August 24, 2007 Share Posted August 24, 2007 Why store days/minutes/hours/seconds? Surely you're better off storing a unix timestamp? Link to comment https://forums.phpfreaks.com/topic/66549-php-comparing-time-for-custom-session-timeouts/#findComment-333333 Share on other sites More sharing options...
Caesar Posted August 24, 2007 Share Posted August 24, 2007 I agree... A simple timestamp will do. <?php function check_session($current) { session_start(); $sess_limit = 1200; $sess_start = $_SESSION['sess_start']; $session_time = ($current - $sess_start); if($session_time > $sess_limit) { session_destroy(); header("location: index.php?action=logout"); exit; } else { //Update the your session...or whatever. } } ?> Link to comment https://forums.phpfreaks.com/topic/66549-php-comparing-time-for-custom-session-timeouts/#findComment-333335 Share on other sites More sharing options...
JoelRocks Posted August 25, 2007 Author Share Posted August 25, 2007 Thanks all, 1200 is.... how many minutes??? Link to comment https://forums.phpfreaks.com/topic/66549-php-comparing-time-for-custom-session-timeouts/#findComment-333778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.