Page 1 of 1
timers counting down on a still page
Posted: Mon Jan 11, 2010 3:48 pm
by chopficaro
my friend is all asp, and he made these timers that count down as soon as the page is loaded. like u load the page and everything on the page is still except for this timer counting down hours minuits and seconds. is there a way to do this in php?
Re: timers counting down on a still page
Posted: Mon Jan 11, 2010 6:32 pm
by Grizzzzzzzzzz
As far as i know, no. PHP is all about running serverside on request and then providing output, it doesn't run clientside, so cannot act past the inital request.
You can in javascript though, and very easily too.
Re: timers counting down on a still page
Posted: Mon Jan 11, 2010 6:34 pm
by SimpleManWeb
Re: timers counting down on a still page
Posted: Mon Jan 11, 2010 9:12 pm
by SidewinderX
Grizzzzzzzzzz wrote:As far as i know, no. PHP is all about running serverside on request and then providing output, it doesn't run clientside, so cannot act past the inital request.
You can in javascript though, and very easily too.
Technically speaking, you are correct. However, I was surprised when I saw the results of the following code (in firefox).
Code: Select all
<?php
ob_end_flush();
$count = 10;
for($i = 1; $i <= $count; $i++) {
sleep(1);
echo $i;
flush();
}
?>
Re: timers counting down on a still page
Posted: Mon Jan 11, 2010 11:33 pm
by JNettles
Nothing like having your script run for a full ten seconds.

Re: timers counting down on a still page
Posted: Mon Jan 11, 2010 11:34 pm
by SidewinderX
Indeed. Still pretty neat though.
Re: timers counting down on a still page
Posted: Tue Jan 12, 2010 5:03 am
by Grizzzzzzzzzz
If you REALLLLLLLLLLLLLLLLLY wanted to get a php clock/timer, you could always.....
Code: Select all
<?php
echo date("H:i:s");
echo "<meta http-equiv=\"refresh\" content=\"1\"/>";
?>
but as with the other work-a-round, it's terrible and you'd be much better off with javascript.
Re: timers counting down on a still page
Posted: Tue Jan 12, 2010 6:30 am
by chopficaro
thanks guys ill try out the javascript