1

Is it possible to create a timer using PHP so that after 60 seconds it does something. So it actually shows you a countdown from 60 to 0. I would refresh the div so it actually looks like it's counting down. I don't mind using JavaScript but I want to run the timer only when the $_GET variable is = to something.

For either option, can anyone help?

For now, I'm using this code I got from EpicSoftworks on Youtube but the problem with this code is that you have to specify the timestamp you want to use.

$future = -2211753540;
$current = time();
$difference = $future - $current;

$minutes = floor($difference/60);
$r_seconds = floor($difference - ($minutes = 60) );

echo '<h2>' . $minutes . ' - ' . $r_seconds . '</h4>';
5
  • 2
    write some code first, update your post, then we can help Commented Mar 19, 2013 at 20:17
  • 2
    PHP is server side code. It would be pointless to make a call to the server every second to just countdown by 1. Use javascript and refresh or do something after the count Commented Mar 19, 2013 at 20:19
  • Whatever you end up with, careful with PHP's max_execution_time Commented Mar 19, 2013 at 20:21
  • 1
    use javascript, it's better for this case Commented Mar 19, 2013 at 20:22
  • I think that this is the right exercise for you to learn about the singleton pattern, since you want to do something with javascript Commented Mar 19, 2013 at 20:27

1 Answer 1

3

use PHP to get the variable from the URL and then use javascript for the rest. Create a function that will run a loop 60 times. Inside that loop create a setTimeOut that will do something with a 1000 (1 second) timeout.

Sign up to request clarification or add additional context in comments.

1 Comment

while in javascript, you wont make useless trafiic to the server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.