Reputation: 1979
I need to destroy the session if the user is idle up to 10 minutes also how to find the time of last activity of the user ,
if ($_SESSION['last_activity'] > 600)
{
session_unset();
session_destroy();
}
is this correct way..
Upvotes: 1
Views: 599
Reputation: 3417
Use session.gc_maxlifetime
Set session.gc_maxlifetime = 600 in phi.ini
or
ini_set('session.gc_maxlifetime',600); // in your script
Upvotes: 2
Reputation: 72857
Check for activity before resetting the time:
if (isset($_SESSION['last_activity']) && $_SESSION['last_activity'] > 600){
session_unset();
session_destroy();
}else{
$_SESSION['last_activity'] = time();
}
Upvotes: 0
Reputation: 33
//on pageload
session_start();
$idletime=60;//after 60 seconds the user gets logged out
if (time()-$_SESSION['timestamp']>$idletime){
session_destroy();
session_unset();
}else{
$_SESSION['timestamp']=time();
}
//on session creation
$_SESSION['timestamp']=time();
Upvotes: 0