PHP中的会话超时

问题描述:

HI, i have code for session time out but i dont know whats the issue its not working someone pls look at this and help me. Here is the code:

  $inactive = 10;

  // check to see if $_SESSION['timeout'] is set

  if(isset($_SESSION['timeout']) ) {

  $session_life = time() - $_SESSION['timeout'];

  if($session_life > $inactive)

  { 
      session_destroy(); 
      header("Location: logoutpage.php"); }
   }

  $_SESSION['timeout'] = time();

Thanks.

HI, i有会话超时的代码,但我不知道它的问题是什么不工作的人请看看 这个并帮助我。 下面是代码: p>

  $ inactive = 10; 
 
 //检查$ _SESSION ['timeout']是否设置
 
 if(isset)  ($ _SESSION ['timeout'])){
 
 $ session_life = time() -  $ _SESSION ['timeout']; 
 
 if($ session_life> $ inactive)
 
 {
  session_destroy();  
 header(“Location:logoutpage.php”);  } 
} 
 
 $ _SESSION ['timeout'] = time(); 
  code>  pre> 
 
 

谢谢。 p> div>

the time() variable returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). Your $inactive variable implies you wish to keep sessions open for 10 minutes, but you might find it more convenient to switch this to seconds to stay consistent with using the time() function.

// set inactive to 10 minutes (in seconds)
$inactive = 600;

if (!empty($_SESSION['timeout'])) {

    // set session life to current time minus timeout
    $session_life = time() - $_SESSION['timeout'];

    // check if your session life is greater than 10 minutes
    if ($session_life > $inactive) {
        session_destroy();
        header("Location: logoutpage.php");
        die;
    }

}

$_SESSION['timeout'] = time();