2017-02-24 65 views

回答

0

一旦瀏覽器關閉,會話變量就會過期。如果你仍然想要會話變量,你應該使用cookies。將會話值存儲在Cookie中,並在需要時訪問Cookie。設置session.cookie_lifetime爲非零,以便cookie不會過期。有關存儲和訪問的詳細信息請參見餅乾和php cookiesphp session cookie

0

使用永葆: 例:

session_start(); 
$_SESSION["timeout"] = time(); 

//if 100 seconds have passed since creating session delete it. Use math to figure out minutes and hours 
if(time() - $_SESSION["timeout"] > 100){ 
    unset($_SESSION["timeout"]; 
} 

但是這可能會回答你的問題,但它不是一個好的選擇。 您的服務器在內存中保留會話並且太多會導致您的服務器減慢一些。

如果你想保持有關信息登錄即使在關閉瀏覽器使用Cookie

setcookie("email-","dummytext",time()-60*60*24*365,str_replace(".","_",$_SERVER['SERVER_NAME']),0); 

退房setcookie();

立即檢查該網頁的餅乾開始

if(!empty($_COOKIE['email-'.str_replace(".","_",$_SERVER['SERVER_NAME'])]) // checks for cookie email- 

http://php.net/manual/en/function.setcookie.php