简体   繁体   中英

Time in a variable, decrease a delay

I have a time() value saved in a variable like this:

$latest_attempt = 1337980678;

I am trying to calculate some delay.

$remaining_delay = time() - $latest_attempt - $delay;

However the result of $remaining_delay is increasing when I update the browser, and not the way around.

"You must wait 95 seconds before your next login attempt"

If I update some seconds later "You must wait 102 seconds before your next login attempt"

It's doing the opposite what it should doing, instead it would rather decrease than increase. What have I done wrong? I believe I need to do something with latest_attempt variable, but I could not find anything i the php manual.

我要说的是这样的:

$remaining_delay = $latest_attempt + $delay - time();
$time_since_last = time() - $last_attempt;

if ($time_since_last <= $delay) {
    $remaining = $delay - $time_since_last;
} else {
   ... good to go ... delay's expired
}

The remaining delay is the difference between that moment in time when the blockage expires ( $last_attempt + $delay because from $last_attempt on, the user is blocked for a period of $delay) and the current time ( time() ) - therefore the correct formula is:

$remaining_delay = ($latest_attempt + $delay) - time();

if ($remaining_delay > 0) {
    die('Access denied, you need to wait another '. $remaining_delay .' seconds');
}

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