Created
May 27, 2014 22:05
-
-
Save stojg/0ad4a8b45c80b194f5ba to your computer and use it in GitHub Desktop.
session timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function start_session($timeout = 1800) | |
{ | |
session_cache_limiter(false); | |
session_start(); | |
ini_set("session.gc_maxlifetime", $timeout); | |
if (isset($_SESSION['lastSeen'])) { | |
$heartbeatAgo = time() - $_SESSION['lastSeen']; | |
$timeLeft = $timeout - $heartbeatAgo; | |
if ($timeLeft < 0) { | |
$_SESSION = array(); | |
} | |
} | |
$_SESSION['lastSeen'] = time(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment