Skip to content

Instantly share code, notes, and snippets.

@stojg
Created May 27, 2014 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stojg/0ad4a8b45c80b194f5ba to your computer and use it in GitHub Desktop.
Save stojg/0ad4a8b45c80b194f5ba to your computer and use it in GitHub Desktop.
session timeout
<?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