简体   繁体   English

如何在php中测试会话超时?

[英]How to test session timeout in php?

Why doesn't this code work?为什么这段代码不起作用?

session_start();

// 5 mins in seconds
$inactive = 300; 
$session_life = time() - $_session['timeout'];
if($session_life > $inactive)
{  
    session_destroy(); header("Location: client_login.php");     
} 
else 
{
    $_session['timeout']=time();
}

Check :查看 :

print_r($_SESSION) and print_r($_SESSION['timeout']) print_r($_SESSION)print_r($_SESSION['timeout'])

you can var_dump( $_session );你可以var_dump( $_session ); after your if/else statement and see if $_session['timeout'] is set or has a value.在您的 if/else 语句之后,看看$_session['timeout']是否已设置或具有值。 following session_destroy() the session should be empty.session_destroy() ,会话应该是空的。

update更新

Try changing $_session to $_SESSION .尝试将$_session更改$_session $_SESSION This is a special PHP variable and case may matter这是一个特殊的 PHP 变量,大小写可能很重要

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM