Is there any option to destroy a session if user does not perform any action in 10 minutes?
You can decide the timeout with a function. Then set a session variable called 'timeout' in the session Now put a condition of timeout. If satisfied, it will destroy your session.
A PHP session can be destroyed by session_destroy() function. This function does not need any argument and a single call can destroy all the session variables. If you want to destroy a single session variable then you can use unset() function to unset a session variable.
The session timeout is used to set the time limit for the inactivity of the user. Suppose, if the session timeout limit is set to 60 seconds and the user is inactive for 60 seconds then the session of that user will be expired and the user will require to log in again to access the site.
Browsers deletes the session cookies when the browser is closed, if you close it normally and not only kills the process, so the session is permanently lost on the client side when the browser is closed.
Try setting the session timeout to 10 minutes.
ini_set('session.gc_maxlifetime',10);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With