Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-29-2010, 10:25 PM   PM User | #1
just cool
New to the CF scene

 
Join Date: Mar 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
just cool is an unknown quantity at this point
Smile Looking for a Countdown Timer to reset itself daily at midnight

I currently have a timer but its in Javascript so it works only on the clients computer time but i need it to work with the server time so that i can set it to a timezone and make sure that it resets itself at midnight EST time no matter what time zone you are in. I was told its better to use PHP for this countdown to work properly but im a very newbie in PHP.

Can someone indicate a script that i can use ..... PLEASE
just cool is offline   Reply With Quote
Old 03-29-2010, 11:20 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Hmm, lets see if this works:
PHP Code:
$iTimeTo strtotime("00:00 tomorrow");
$iDiffTime $iTimeTo time();

printf("Remaining: %s\n"date('H:i:s'$iDiffTime)); 
That work?
I'm a little curious if the 00:00 is valid with the tomorrow modifier. I believe it is in the GNU but I could be mistaken. If not, we'll find another mktime based solution.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 03-29-2010, 11:46 PM   PM User | #3
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
And here is a code snippet for EST, just put it in your header.php file and all PHP dates will be in EST.

PHP Code:
date_default_timezone_set('America/New_York'); 

----------------
__________________
Leonard Whistler
Len Whistler is offline   Reply With Quote
Old 03-30-2010, 04:43 AM   PM User | #4
just cool
New to the CF scene

 
Join Date: Mar 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
just cool is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
Hmm, lets see if this works:
PHP Code:
$iTimeTo strtotime("00:00 tomorrow");
$iDiffTime $iTimeTo time();

printf("Remaining: %s\n"date('H:i:s'$iDiffTime)); 
That work?
I'm a little curious if the 00:00 is valid with the tomorrow modifier. I believe it is in the GNU but I could be mistaken. If not, we'll find another mktime based solution.
Fou-Lu i did try what you give me but it did not work. Actually i tried it at 10:42 pm EST and when i load a demo page to see the script in action the time was 19:24:54 which is the wrong time and its not counting down as well. It just stays there until i refresh the page. What i want is for the time to keep counting down by the second and it refresh itself at midnight to 23:59:59 and counts down again each day and it must be seen counting down on the webpage.
just cool is offline   Reply With Quote
Old 03-30-2010, 04:50 AM   PM User | #5
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
What exactly is the timer doing? Counting up? Down? What determines the count? Does it start at zero and increment by the second? Does it start at 100 and decrement every so many seconds, minutes, hours, etc? How exactly is it supposed to behave? The more we know the better we'll be able to help.
__________________
ZCE

Last edited by kbluhm; 03-30-2010 at 04:53 AM..
kbluhm is offline   Reply With Quote
Old 03-30-2010, 05:16 AM   PM User | #6
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
I would go with an all Javascript solution.


http://articles.techrepublic.com.com...1-6016329.html





--------
__________________
Leonard Whistler
Len Whistler is offline   Reply With Quote
Old 03-30-2010, 12:27 PM   PM User | #7
just cool
New to the CF scene

 
Join Date: Mar 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
just cool is an unknown quantity at this point
Quote:
Originally Posted by kbluhm View Post
What exactly is the timer doing? Counting up? Down? What determines the count? Does it start at zero and increment by the second? Does it start at 100 and decrement every so many seconds, minutes, hours, etc? How exactly is it supposed to behave? The more we know the better we'll be able to help.
I will try to make my request as clear as a i can.

I would like to have a countdown timer on my website that will count down from 12:00:01 am and end at midnight again of the same day (the clock should count down a full 24 hours) then it will automatically reset itself and count down again each and every day. The count down should display hours : minutes : seconds and it should be seen on the webpage counting down as well just like a digital watch but instead of going up its should be counting down to end the day. I would also like to it to go with the server time and not client computer time so it will only count down according to the server time.

One more thing .... each day a new trivia question will be posted and ppl have 1 day to answer the trivia question for a chance to win something (that is why the script is counting down). Will the script be able to automatically load a new trivia each day at midnight as the timer resets or do i have to load the trivia manually? If im getting way out of my head here then lets forget this last part.

I was told it can only be done with PHP but i also see that Len Whistler is talking about JavaScript. However it can be done i will certainly appreciate the advice.
just cool is offline   Reply With Quote
Old 03-30-2010, 03:57 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I'm half suprised that that gave you a number in the first place! Wow, learn something new every day!

Ok, lets take a look. At this point, we have no idea if the code I provided for you is actually flawed or not. That is based on Server time and offset, not client time. So, use what Len Whistler provided to change you're offset to a valid EST timezone. Next, modify the code I provided to this:

PHP Code:
$iTimeTo strtotime("00:00 tomorrow"); 
$iDiffTime $iTimeTo time(); 

printf("Current Time: %s\n"date('H:i:s'));
printf("Remaining: %s\n"date('H:i:s'$iDiffTime)); 
That will also show you what the current time is. Compare the Remaining to the Current to see if its actually functional or not.

As for the questions, yes that can only really be controlled with PHP; Javascript can display these and whatnots, but there is no guarentee that the user cannot go back. That can be done easily as well, but you'll need a datasource of some sorts to store this in. As for an actual 'count down', PHP is not capable of performing this. Being a server side language, all you can ask for is data, not dynamic updates. What you can do is pass data to Javascript and let it count.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 03-30-2010, 04:22 PM   PM User | #9
DJCMBear
Senior Coder

 
DJCMBear's Avatar
 
Join Date: Mar 2010
Location: United Kindom
Posts: 1,173
Thanks: 14
Thanked 136 Times in 136 Posts
DJCMBear is on a distinguished road
To get your current time to set right use this:
PHP Code:
<?php 
date_default_timezone_set
("EST");
?>
And to see the countdown working on the page without refreshing you will need to use javascript as php isn't client-side and javascript is.

You can use your php codes to generate the times for the javascript to use and then use javascript to count the time down.
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
DJCMBear is offline   Reply With Quote
Old 03-30-2010, 05:11 PM   PM User | #10
sitNsmile
Regular Coder

 
sitNsmile's Avatar
 
Join Date: Dec 2009
Location: Charlotte, NC
Posts: 354
Thanks: 19
Thanked 2 Times in 2 Posts
sitNsmile is an unknown quantity at this point
You cant make a script to reset anything on its own at the time you wish. You'd need to of course have the script do the reset function which are said in previous replies, but you would need to put this into the "Cronjob" to tell it to run that script at the time you wish (midnight) which automatically tells it to use server time.
sitNsmile is offline   Reply With Quote
Old 03-31-2010, 12:21 AM   PM User | #11
just cool
New to the CF scene

 
Join Date: Mar 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
just cool is an unknown quantity at this point
Well i guess that what i wanted to get done will have to be done in JavaScript so i would post it in the JavaScript section and see if i can get any help there.

A Special Thank You to ALL who tried to help me and i appreciate it very well.
just cool is offline   Reply With Quote
Old 03-03-2011, 01:31 PM   PM User | #12
dados
New to the CF scene

 
Join Date: Mar 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
dados can only hope to improve
Hi to everybody I need to all same thing Countdown Timer to reset itself daily at midnight and count time by server.. Can please send me the script if somebody have this?
dados is offline   Reply With Quote
Old 03-04-2011, 12:47 AM   PM User | #13
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
You can't reset the timer "automatically" but you can make it so when the user visits the page it resets itself without any action by the user. I don't have the ability for Cronjobs on my host (at this time), so most of my scripts are automatically ran when a user visits my website.

So in turn, it can be done via PHP. Just a matter of when you want it to reset to countdown?
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:29 PM.


Advertisement
Log in to turn off these ads.