[英]Strtotime not working as expected
My goal is to compare the current time with the last visited time and if was 5 minutes ago then allow to visit again, else, deny! 我的目标是将当前时间与上次访问的时间进行比较,如果是5分钟前,则允许再次访问,否则,拒绝! Here what I have so far
这是我到目前为止所拥有的
$last_activate = strtotime($last_activ); //$last_activ is TIMESTAMP value retrieved from MySQL database
$current_time = strtotime('now');
if(($current_time - $last_activate) > strtotime('5 minutes')){
//allow access
}
else{
//deny access
}
At the moment, the code above always executes else
statement even if $last_activate
was 24 hours ago. 目前,即使
$last_activate
是24小时前,上面的代码也总是执行else
语句。 Anyone knows what point I am missing? 有人知道我缺少什么吗?
strtotime('5 minutes')
means now + 5 minutes
. strtotime('5 minutes')
表示now + 5 minutes
。 Proof: 证明:
echo date("Y-m-d H:i:s", strtotime('5 minutes'));
2013-03-21 19:41:27
Do this instead: 改为这样做:
if(($current_time - $last_activate) > 5 * 60){
将5 minutes
替换为5 minutes ago
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.