简体   繁体   中英

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! 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. Anyone knows what point I am missing?

strtotime('5 minutes') means 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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