user27838
0
Q:

php set session timeout

//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
0
<?php  
  
// Session starts 
session_start();  
$username = $_POST["username"]; 
  
if(isset($_POST["Login"])) { 
  
    // Session Variables are created 
    $_SESSION["user"] = $username;    
  
    // Login time is stored in a session variable 
    $_SESSION["login_time_stamp"] = time();   
    header("Location:homepage.php"); 
} 
?> 
0
<?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"); 
} 
?> 
0

New to Communities?

Join the community