PHP oturum zaman aşımı

1 Cevap

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();

Teşekkürler.

1 Cevap

time() değişkeni Unix Epoch beri saniye sayısıyla ölçülür şimdiki zaman (1 Ocak 1970 00:00:00 GMT) döndürür. Sizin $inactive değişken, 10 dakika boyunca açık oturumları tutmak isteyen, ancak zaman () fonksiyonu kullanarak tutarlı kalmak için saniye bu geçiş daha rahat bulabilirsiniz ima eder.

// 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();