timers counting down on a still page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chopficaro
Forum Commoner
Posts: 68
Joined: Fri Jan 01, 2010 12:56 am

timers counting down on a still page

Post 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?
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: timers counting down on a still page

Post 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.
Last edited by Grizzzzzzzzzz on Mon Jan 11, 2010 6:34 pm, edited 1 time in total.
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: timers counting down on a still page

Post by SimpleManWeb »

SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: timers counting down on a still page

Post 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();
}
?>
 
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: timers counting down on a still page

Post by JNettles »

Nothing like having your script run for a full ten seconds. :wink:
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: timers counting down on a still page

Post by SidewinderX »

Indeed. Still pretty neat though.
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: timers counting down on a still page

Post 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.
chopficaro
Forum Commoner
Posts: 68
Joined: Fri Jan 01, 2010 12:56 am

Re: timers counting down on a still page

Post by chopficaro »

thanks guys ill try out the javascript
Post Reply