2017-07-08 26 views
0

我嘗試atmost,但我沒有在1分鐘內銷燬會話。我正在使用下面給出的PHP銷燬代碼,但它不起作用。如何在1分鐘內銷燬會話?

<?php 
    session_start(); 
    $_SESSION['start'] = "start session"; 
    if(isset($_POST['destroy'])){ 
     session_cache_expire(1); 
    } 
?>  
+0

按照此鏈接 - https://stackoverflow.com/questions/17179249/session-destroy- after-certain-amount-of-time-in-php –

+0

[如何在30分鐘後過期PHP會話?](https://stackoverflow.com/q/520237/6521116) –

+3

在[PHP]中經過一段時間後會出現[session \ _destroy()的可能重複](https://stackoverflow.com/questions/17179249/session-destroy-after-certain-amount-of-time-in-php) –

回答

0
session_start(); 

// 1 mins in seconds 
$inactive = 60; 

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

if($session_life > $inactive) 
{ session_destroy(); header("Location: logoutpage.php");  } 

S_session['timeout']=time(); 

請參閱本link

,或者您可以使用

ini_set('session.gc_maxlifetime',1); 
0
 <?php 
     define("DURATION",'1'); // define duration constant in minutes 
     session_start(); 
     $duration = (DURATION * 60); // duration in seconds 

     if(isset($_SESSION['started'])) //check whether session is set or not 
     { 
      $time = ($duration - (time() - $_SESSION['started'])); 
      if($time <= 0) 
      { 
       session_destroy(); 
       echo "Session has been expired. You were logged in for one minute"; 
      } 
     } 
     else 
     { 
      $_SESSION['started'] = time(); 
     } 
     ?>