PHP Countdown Timer

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
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

PHP Countdown Timer

Post by barrowvian »

I've been having a quick look around the internet and have found a few of these, but I'm looking for something a little more specific;

I'm wanting a countdown timer that will let me count down 24 hours, once the timer reaches 0 then the current page (where the countdown timer is located) will redirect to a new page when someone tries to view it, and/or will refresh and redirect if someone is still active on the page once the countdown has finished.

Is this possible to make in PHP or would a different language be more efficient?

Thanks
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: PHP Countdown Timer

Post by Grizzzzzzzzzz »

you'd be better off in javascript
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

Re: PHP Countdown Timer

Post by barrowvian »

Yea a few people I have spoken to have said javascript would be the best route for the timer, however, I'm lead to believe that with javascript being client side that it will run off of the users own clock and that it will restart from scratch when the page is reloaded? If this is the case then it isn't the correct option for this type of timer.

Would there be any way to make a timer using php so that the clock will run continuously (even if the page is not being viewed)? And then when it reaches zero incorporate another function to take over and do the redirect?
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: PHP Countdown Timer

Post by dejvos »

I am afraid there is not such a functionality. PHP is server side thats mean: When page is generated PHP loses control of the page. You have to use some client side solution. If you are afraid of the time of the client computer you would wrote a Javascript function (Java applet, ... ) which would remember a time when the page was generated and ask server about current time. Than you can substract current time and the time when page was generated ... and thats it ... pretty complicated solution but I think it's only think you can do.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: PHP Countdown Timer

Post by flying_circus »

barrowvian wrote:I've been having a quick look around the internet and have found a few of these, but I'm looking for something a little more specific;

I'm wanting a countdown timer that will let me count down 24 hours, once the timer reaches 0 then the current page (where the countdown timer is located) will redirect to a new page when someone tries to view it, and/or will refresh and redirect if someone is still active on the page once the countdown has finished.

Is this possible to make in PHP or would a different language be more efficient?

Thanks
You could create and store a timestamp for the start of your 24 hour period. On every page request, your script would compare the current time to the stored timestamp. If 24 hours have elapsed, then it can redirect that user to a different page.

As far as forcing a page to refresh after 24 hours, there is no reliable way to do this.
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: PHP Countdown Timer

Post by Grizzzzzzzzzz »

As far as forcing a page to refresh after 24 hours, there is no reliable way to do this.
Simple as sin, but couldn't you grab the remaining number of seconds in a PHP variable and simply output it on the page

Code: Select all

 
print "<meta http-equiv=\"refresh\" content=\"".$remainingSeconds."\">";
 
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: PHP Countdown Timer

Post by flying_circus »

As far as I understand it, Meta Refresh has been deprecated for a while now.
Post Reply