Jump to content

a countdown timer


farshad_momtaz

Recommended Posts

hi,

i need a timer that count down the time from 30 to 0 and if the timer is zero the script run php code # 1 ( the timer will stop and if user refreshes the page it is still zero) and if the user hit button # 1 the timer will restart to 30 and the script will run php code # 2 ( the timer will count down again until it is zero). i want the script to work between 1 pm to 3pm(so it starts automatically i at 1)and if the timer didn't get to zero until 3pm i want it to stop counting down and show a message or goes to a different page.

and obviously the timer should show a same number for all the users!

is there any way to do that and if yes how?

can i do it with ajax and if yes how?

 

thank you

 

farshad

Link to comment
Share on other sites

If you want to do this in php you need something like the following:

 

endtime = (timecode of endtime)
current_time = time()

if (current_time >= endtime) {
  echo('TIMER EXPIRED');
} else {
  echo('time remaining: '.(endtime - current_time));
}

 

endtime for 30 seconds from now would be:

 

time() + 30, but if you do this on the page that the timer is calculated it will never expire you need to save it somewhere.

Link to comment
Share on other sites

thanks for you answer but the code that you just gave me have 2 problems

1- it doesn't count it down it just shows the number so the user have to refresh to get the new number

2- even user number one presses the reset button user number 2 have to refresh the page to see that the timer was reset

 

Link to comment
Share on other sites

this is an understand able version of what i just said :)

I am making a website and the page is oriented around a countdown system. If the timer ever reaches 0, the whole thing will stop. Below are the specifics:

 

I need a countdown timer that runs from 30 seconds to 0 seconds. If the timer is at 0 seconds, the script runs php code #1 (which makes the timer stop and if any user refreshes the page, it will still stay at zero).

There is also two buttons. If user clicks on button #1, the timer will get reset to 30 seconds remaining. Then the script will run the php code #2 (which allows the timer to begin counting down again from 30 seconds). If user clicks on button #2, the timer will get reset to 5 seconds remaining and same thing follows as the first button.

 

I want the timer counter script to between before certain hours (like let's say, noon-4PM). I want the counter to automatically begin at Noon with the above instructions. Also, if by 4PM, the counter never reaches 0 (meaning it never reaches php code #1), I want the timer counter to stop, disappear, and a message appear over it to link it to a new page.

 

And obviously the timer should show the same number (seconds remaining) for all the users on the website!

Link to comment
Share on other sites

you wont get that; php is done SERVER SIDE the clients never see it,

 

The only thoing you could do and still use php is:

 

<?php
header('refresh: this.page.php; time=5');
?>

 

HOWEVER YOU MAY NEED TO CHECK THE SYNTAX, i dont use refresh, never needed to, sounds like you want javascript, but i am not sure if it has the power to make everything stop, and that is client side, however clients can just turn it off. the javascript that is.

Link to comment
Share on other sites

ok i made a javascript code that is a simple timer and it counts down to zero but the problem is the problem with that is when i refresh the page it goes back to 30 so there isn't a point in that and when another users is in the page our timers doesn't show the same time!!

and by the way cant i use the technology that is used in chat rooms or online chats?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.