【发布时间】:2015-09-08 15:28:12
【问题描述】:
我正在开始会话
session_start(); //So This session will get destroyed when user exit the browser
我将cookie设置为
setcookie('cookie',$value,time()+3*60);
$_SESSION['cookie'] = true; //When user log in, I don't need to get the
salt again from db and do all the security
checks. Assume it as a cache
此建议在this question 中提出。
问题是,cookie 在 3 分钟后过期。但是会话存在。所以用户在 3 分钟后尝试登录
if($_SESSION['cookie'])
{
//success
}
else
{
//Authenticate user
}
但这是错误的。由于 cookie 过期,else 部分应该执行。但是如果部分被执行。我知道该会话仍然存在。我该如何处理这种情况?
我知道这是由于time()+3*60。但是我该如何实现那个缓存呢?
【问题讨论】:
-
$_SESSION['cookie']与cookie无关。 -
time()*3*60不是 3 分钟。 -
要在 3 分钟内过期,它应该是
time() + 3*60-- 相加,而不是相乘。 -
请查看编辑。谢谢巴尔默