Freid001 Posted July 31, 2010 Share Posted July 31, 2010 Does any one know a php or html 30 second countdown script? thanks Quote Link to comment Share on other sites More sharing options...
jcbones Posted July 31, 2010 Share Posted July 31, 2010 This script uses php and javascript, and I set it to 30 seconds for you. It uses sessions so that if you refresh the page, it will keep the countdown. After reaching 0 it will remain, until a page refresh, then it returns to the 30 second countdown. <?php session_start(); $timestamp = time(); $diff = 30; if(isset($_SESSION['ts'])) { $slice = ($timestamp - $_SESSION['ts']); $diff = $diff - $slice; } if(!isset($_SESSION['ts']) || $diff > 30 || $diff < 0) { $diff = 30; $_SESSION['ts'] = $timestamp; } //Below is demonstration of output. Seconds could be passed to Javascript. $diff; //$diff holds seconds less than 3600 (1 hour); $hours = floor($diff / 3600) . ' : '; $diff = $diff % 3600; $minutes = floor($diff / 60) . ' : '; $diff = $diff % 60; $seconds = $diff; ?> <div id="strclock">Clock Here!</div> <script type="text/javascript"> var hour = <?php echo floor($hours); ?>; var min = <?php echo floor($minutes); ?>; var sec = <?php echo floor($seconds); ?> function countdown() { if(sec <= 0 && min > 0) { sec = 59; min -= 1; } else if(min <= 0 && sec <= 0) { min = 0; sec = 0; } else { sec -= 1; } if(min <= 0 && hour > 0) { min = 59; hour -= 1; } var pat = /^[0-9]{1}$/; sec = (pat.test(sec) == true) ? '0'+sec : sec; min = (pat.test(min) == true) ? '0'+min : min; hour = (pat.test(hour) == true) ? '0'+hour : hour; document.getElementById('strclock').innerHTML = hour+":"+min+":"+sec; setTimeout("countdown()",1000); } countdown(); </script> Quote Link to comment Share on other sites More sharing options...
Freid001 Posted July 31, 2010 Author Share Posted July 31, 2010 I cant seem to get it working??? It just says Clock Here? Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted July 31, 2010 Share Posted July 31, 2010 well as mentioned by the poster of the script it requires both PHP and Javascript to run. One thing the person failed to mention is with the script posted you need a display element on your page hidden or otherwise with the id="" part of the element being id="strclock" what the php part of the script does is break the time down and find the difference between the given time and the count down time then echoed into the value area of the given element with id="strclock" as its ID. The JavaScript will then find the information within that element the way the JavaScript is devices I would suggest using a div as your display element. And will simulate a countdown visually of the desired countdown you want. In a matter of opinion I think this is a bit over kill. I would say depending on what your trying to do with a countdown your best bet would be just to use javascript completely to handle what you want to do. PHP only runs once and thats while the page is loading. Its constructing the given page to be displayed server side. Where as Javascript can manipulate a page as much as you want after the page has been loaded client side. Quote Link to comment Share on other sites More sharing options...
Freid001 Posted July 31, 2010 Author Share Posted July 31, 2010 ok do you know where i can get a java count down? Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted August 1, 2010 Share Posted August 1, 2010 Im almost positive they have something here.. http://dynamicdrive.com/ This sites been around for years has a bunch of canned code layin about ripe for the picking. Most of the code there is dated but still working, others leave room for improvement. But you can deffinately find what your looking for there.. worse comes to worse, google is very handy just key in "Javascript Countdown" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.