PHP 会话在 5 分钟后过期
我有以下代码可以在设定的时间后使会话过期。然而它无法正常工作。如果我将其设置为例如 1 分钟甚至 5 分钟,它会立即过期。你能帮忙吗?
// duration in minutes * seconds
$duration = (DURATION * 60);
if(isset($_SESSION['started']))
{
// show banner and hide form
echo $msg;
$showform = 0;
if((time() - $_SESSION['started'] - $duration) > 0)
{
unset($_SESSION['count']);
unset($_SESSION['offender']);
$showform = 1;
}
}
else
{
$_SESSION['started'] = time();
}
I have the following code to expire a session after set amount of time. It is however not working properly. If I set it for example for 1 minute or even 5 minute, it expires immediately. Can you help?
// duration in minutes * seconds
$duration = (DURATION * 60);
if(isset($_SESSION['started']))
{
// show banner and hide form
echo $msg;
$showform = 0;
if((time() - $_SESSION['started'] - $duration) > 0)
{
unset($_SESSION['count']);
unset($_SESSION['offender']);
$showform = 1;
}
}
else
{
$_SESSION['started'] = time();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
稍微修改一下你的代码看看。这应该有效。
Modified your code little bit take a look. This should work.