PHP - Destroy session if not any action in 10 minutes
i've modified the answer above, and it works fine :
// inactive in seconds
$inactive = 10;
if( !isset($_SESSION['timeout']) )
$_SESSION['timeout'] = time() + $inactive;
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive)
{ session_destroy(); header("Location:index.php"); }
$_SESSION['timeout']=time();
I've done it with the following code:
//10 min
if( !isset($_SESSION['logout']) ){
$_SESSION['logout'] = strtotime('+10 minutes', time());
}
if( time() > $_SESSION['logout'])
{
session_destroy();
header("Location: index.php");
}else{
$_SESSION['logout'] = strtotime('+10 minutes', time());
}
//echo date('Y/m/d h:i:s',$_SESSION['logout']);
//echo $_SESSION['logout'];
session_start();
// 10 mins in seconds
$inactive = 600;
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive) {
session_destroy();
header("Location: logoutpage.php");
}
$_SESSION['timeout']=time();
The code above was taken from this particular page.
Try setting the session timeout to 10 minutes.
ini_set('session.gc_maxlifetime',10);