0

I am making a php timer that i refresh with ajax every second on my page. But i am having problems getting it to work. I need it to countdown 8 minutes. This is the script

<?php
$saveTime = (3600*10); // Saved time from file/database
$thisTime = time(); // Current time
$diffTime = ($saveTime-$thisTime); // Difference in time
if($diffTime >= 1) {
    $countMin = floor($diffTime/60);
    $countSec = ($diffTime-($countMin*60));
    echo 'Time remaining until next run is in ',$countMin,' minute(s) ',$countSec,' seconds';
} else {
    echo 'Timer expired.';
}
?>
user3064914
  • 921
  • 1
  • 7
  • 18

1 Answers1

1

Your problem is in the value saved in the $saveTime variable.

time() returns the number of seconds since 1st January 1970. Your value for $saveTime is about 10am on that day.

You need to set $saveTime to some time in the future. For example,

$saveTime = time()+(8*60);  // 8 minutes into the future.