php set session timeout
snippet in php

php set session timeout

user5731

//Ending a php session after 30 minutes of inactivity
$minutesBeforeSessionExpire=30;
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > ($minutesBeforeSessionExpire*60))) {
    session_unset();     // unset $_SESSION   
    session_destroy();   // destroy session data  
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity

set session timeout php

user8582

<?php  
  
session_start(); 
  
// To check if session is started. 
if(isset($_SESSION["user"]))  
{ 
    if(time()-$_SESSION["login_time_stamp"] >600)   
    { 
        session_unset(); 
        session_destroy(); 
        header("Location:login.php"); 
    } 
} 
else
{ 
    header("Location:login.php"); 
} 
?>