2017-02-24 72 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