PHP - How Do I Implement This Countdown Timer Code?
Hi again people!
I found this code that codes for a countdown timer. My problem is, how do I implement it? I've found similar codes that leave me dazzled as I try to get them to work. The URL from which I found this is: http://scripts.franciscocharrua.com/server-side-countdown-clock.php The code is: Code: [Select] function countdown_clock(year, month, day, hour, minute, format) { //I chose a div as the container for the timer, but //it can be an input tag inside a form, or anything //who's displayed content can be changed through //client-side scripting. html_code = '<div id="countdown"></div>'; document.write(html_code); Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); <? $date = getDate(); $second = $date["seconds"]; $minute = $date["minutes"]; $hour = $date["hours"]; $day = $date["mday"]; $month = $date["mon"]; $month_name = $date["month"]; $year = $date["year"]; ?> //Computes the time difference between the client computer and the server. Server_Date = (new Date(<?= $year - 2000 ?>, <?= $month ?>, <?= $day ?>, <?= $hour ?>, <?= $minute ?>, <?= $second ?>)).getTime(); Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); countdown(year, month, day, hour, minute, (Todays_Date - Server_Date), format); } function countdown(year, month, day, hour, minute, time_difference, format) { Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); //Convert today's date and the target date into miliseconds. Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime(); //Find their difference, and convert that into seconds. //Taking into account the time differential between the client computer and the server. Time_Left = Math.round((Target_Date - Todays_Date + time_difference) / 1000); if(Time_Left < 0) Time_Left = 0; switch(format) { case 0: //The simplest way to display the time left. document.all.countdown.innerHTML = Time_Left + ' seconds'; break; case 1: //More datailed. days = Math.floor(Time_Left / (60 * 60 * 24)); Time_Left %= (60 * 60 * 24); hours = Math.floor(Time_Left / (60 * 60)); Time_Left %= (60 * 60); minutes = Math.floor(Time_Left / 60); Time_Left %= 60; seconds = Time_Left; dps = 's'; hps = 's'; mps = 's'; sps = 's'; //ps is short for plural suffix. if(days == 1) dps =''; if(hours == 1) hps =''; if(minutes == 1) mps =''; if(seconds == 1) sps =''; document.all.countdown.innerHTML = days + ' day' + dps + ' '; document.all.countdown.innerHTML += hours + ' hour' + hps + ' '; document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and '; document.all.countdown.innerHTML += seconds + ' second' + sps; break; default: document.all.countdown.innerHTML = Time_Left + ' seconds'; } //Recursive call, keeps the clock ticking. setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + time_difference + ', ' + format + ');', 1000); } I've tried saving the file as a php file and html file, but to no avail... Similar TutorialsCan anyone help me to make a countdown timer in php? so basically i've made a quiz.. but i want it to have a time of 1 hour 30 mins.. but i dont have any idea of how to make a timer Here's the code for the countdown timer. It works. At the end of the countdown, it's suppose to show the message "EXPIRED". But that message only shows once I reload the page. The countdown itself stops at 00:00:01. Is there a way to automatically show the message after that, instead of reloading the page to show it? <style> div#counter{ margin: 100px auto; width: 305px; padding:20px; border:1px solid #000000; } div#counter span{ background-color: #00CAF6; padding:5px; margin:1px; font-size:30px; } </style> <?php $target_date = '2019-01-12 05:40:00'; $timeLeft = (strtotime($target_date) - time()) * 1000; ?> <script src="javascripts/timer.js"></script> <script> $(document).ready(function(){ var timeLeft = <?php echo $timeLeft ; ?>; var timer = new Timer($('#counter'), timeLeft); if (timeLeft <= 0) { $('#counter').text('EXPIRED'); } }); </script> <div id="counter"> <span class="hour">00</span> <span class="min">00</span> <span class="sec">00</span> </div> Edited January 11, 2019 by imgrooot Hi all, I would like to create a timer showing a countdown from 0% to 100% (representing "power") ending at noon GMT on Sunday 4th September. The countdown started a few weeks ago, hence as of 1pm GMT on Tuesday 1st March, the countdown should be at 15% The "power" increases by 5% every 11 days so by my calculations, the percentage in our countdown should increase by 0.01% every 1900.8 seconds. So, with this theory, how would I go about coding it? I guess since I use GMT, I need to take a timestamp in GMT first, then calculate the difference between this and Sunday 4th September at 12.00pm. I am not sure though which format of time/date is best to do the calculation. Would it be better to use Unix time? Any help, suggestions and/or code is greatly appreciated. Skulty Newbie PHP user here, so go easy on me . I've been trying to make a timer that starts on an arbitrary number of seconds, say 10 for example, then counts down to 0 (and refreshes itself every second for the user to see how much time is remaining), and then some more code is executed when 0 is reached. I attempted to do something like: <?php $goal = time() + 10; while($goal - time() >= 0) { echo "$goal - time()"; sleep(1); } ?> This didn't seem to work as my page just took a while to load - I suspect it was going through the entire while loop before displaying anything rather than just dynamically updating the timer every second. Also when I chose 100 instead of 10, the webpage didn't seem to even finish loading. Also it displayed a lot of odd text - not a timer at all! Help would be much appreciated ! Hi Guys! Hoping someone can help me with this. I need to produce a timer which I can embed on a website. It needs to count down the remaining hours until 7pm during the weekdays, then at the weekends count down until 7pm on Monday. Any ideas or points in the right direction would be greatly appreciated! I'm a bit of a newbie! Hey guys. My question is simple. I have a time value of the future, in seconds, that I extract from MySQL. time(); How do I make an interactive countdown timer using it? It should show the numbers ticking away. I tried Javascript, but it doesn't go with the php time layout. Can anyone help me here? Thanks! Hey guys and gals!
I am currently working on implementing the following functionality in one of my pages:
Whenever a person with a specific IP address visits the page, an internal countdown timer of 2 hours should be started. Until that timer is active, the only response from the page ANYONE can get would be a predefined echo value. Once the timer has run out, the normal script execution of the rest of the page should be restored.
Any pointers and tips on how to approach that would be greatly appreciated.
So I have a count down timer on my site. http://fpsboost.net And I am clueless as to how I would set a final date with this. Cant find where it's grabbing the info for "finaldate" or anything like that. Want to set the final date to feb 1st 2015 Javascript newb here. Anyone willing to help would be greatly appreciated. Thanks in advance! Btw, I'm using a generic js countdown timer from: http://hilios.github...uery.countdown/ called "The Final Countdown for jQuery v2.0.4" It was preloaded in a template that I downloaded for my site. Edited by jakobe, 09 December 2014 - 01:09 AM. Hi, This is my first post so dont kill me if i did somthing wrong. Im trying to make a simple php/javascript page that will display the time remaining in each period every day (we have 4 periods per day). I found a nice javascript library from www.hashemian.com and am using the example that he linked to to do multiple countdown timers on one page. The problem i am having is that the only way i can think of to make it so that it counts down to a dynamic date is to specify that date as a variable and then combine it with the string that specifys the rest of the date/time combo for the target date/time. The current live version is at smd75jr.com/test/index2.php The first timer is just a test that im using to make sure i havent completely broken it. THe second timer is the one im trying to troubleshoot, it is currently set for 11:59 PM EST "today". (see code below) Any help would be greatly appreciated!! This is my code: Code: [Select] <html> <head> <title>Multiple Countdown Clocks</title> </head> <body> <div id="clock1">[clock1]</div> <div id="clock2">[clock2]</div> </body> <script language="JavaScript"> StartCountDown("clock1","06/27/2012 9:33 PM -0400") StartCountDown("clock2","periodTest") TodaysDate() //var today = new Date() //var todayMonth = today.getMonth() + 1 //var todayDay = today.getDate() //var todayYear = today.getFullYear() //var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) var periodTest = (todayDate + " 11:59 PM -0400") var periodA1 = (todayDate + " 8:53 AM -0400") var periodA2 = (todayDate + " 10:26 AM -0400") var periodA31 = (todayDate + " 12:32 PM -0400") var periodLunch1 = (todayDate + " 11:00 AM -0400") var periodLunch2 = (todayDate + " 12:32 PM -0400") var periodA32 = (todayDate + " 11:59 AM -0400") var periodA4 = (todayDate + " 2:05 PM -0400") //function Periods(todayDate, periodA1, periodA2, periodA31, periodA32, periodA4, periodB1, periodB2, periodB31, periodB32, periodB4, periodLunch1, periodLunch2, periodSchoolStart, periodSchoolEnd) // { // var today = new Date() // var todayMonth = today.getMonth() + 1 // var todayDay = today.getDate() // var todayYear = today.getFullYear() // var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) // // var periodA1 = (todayDate + " 21:25 PM -0400") // } function TodaysDate(todayDate) { var today = new Date() var todayMonth = today.getMonth() + 1 var todayDay = today.getDate() var todayYear = today.getFullYear() var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) } /* Author: Robert Hashemian (http://www.hashemian.com/) Modified by: Munsifali Rashid (http://www.munit.co.uk/) Modified by: Tilesh Khatri */ function StartCountDown(myDiv,myTargetDate) { var dthen = new Date(myTargetDate); var dnow = new Date(); ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(myDiv,gsecs); } function Calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (s.length < 2) { s = "0" + s; } return (s); } function CountBack(myDiv, secs) { var DisplayStr; var DisplayFormat = "%%D%% Days %%H%%:%%M%%:%%S%%"; DisplayStr = DisplayFormat.replace(/%%D%%/g, Calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, Calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, Calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, Calcage(secs,1,60)); if(secs > 0) { document.getElementById(myDiv).innerHTML = DisplayStr; setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ");", 990); } else { document.getElementById(myDiv).innerHTML = "Period Over"; } } </script> </html> Hey all! In the code in question I echo out individual records of data from MySQL successfully. For each record there is a number which is used as a var in the javascript that does the count-down-timer part. However when I view the resulting page the timer works dynamically only with the first record. With the rest, the timer is static. Code: [Select] <? $result0 = mysql_query("SELECT * FROM table WHERE field='$value'"); while ($riw0 = mysql_fetch_assoc($result0)) { $seconds1 = $riw0['seconds'] ; //// echo out data and set variable for the number of seconds to count down ?> <script language="JavaScript"> var countDownInterval=<?=$seconds1?>; var c_reloadwidth=200 </script> <ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer> <script> var countDownTime=countDownInterval+1; function countDown(){ countDownTime--; if (countDownTime <=0){ countDownTime=countDownInterval; clearTimeout(counter) window.location.href="military3.php" //Redirection URL return } var mins = Math.floor(countDownTime/60) var secs = countDownTime-(mins*60) if (document.all) //if IE 4+ document.all.countDownText.innerText = mins+" minutes "+secs+ " "; else if (document.getElementById) //else if NS6+ document.getElementById("countDownText").innerHTML=mins+" minutes "+secs+ " " else if (document.layers){ document.c_reload.document.c_reload2.document.write('Soldiers will be ready in... <span id="countDownText">'+countDownTime+' </span> seconds') document.c_reload.document.c_reload2.document.close() } counter=setTimeout("countDown()", 1000); } function startit(){ if (document.all||document.getElementById) document.write('Soldiers will be ready in <span id="countDownText">'+countDownTime+' </span> seconds') countDown() } if (document.all||document.getElementById) startit() else window.onload=startit </script> <? } ?> I tried replacing the javascript vars with PHP echoes for unique variables, but then no timer shows up, even static. So could anyone advice me on how I could use this code to apply for all MySQL records? Thanks in advance, Thauwa P.S. If I am unclear with my quandary, do let me know. Thank you. ----------------------------------------------------------this code---------------------------------------------------------------------- <?php if($login_incorrect){ if(isset($_COOKIE['login'])){ if($_COOKIE['login'] < 3){ $attempts = $_COOKIE['login'] + 1; setcookie('login', $attempts, time()+60*10); //set the cookie for 10 minutes with the number of attempts stored } else{ echo 'You are banned for 10 minutes. Try again later'; } } else{ setcookie('login', 1, time()+60*10); //set the cookie for 10 minutes with the initial value of 1 } } ?> ----------------------------------------------------in here---------------------------------------------------------------------------------- include('dbc.php'); if(isset($_POST['login'])) { $username=$_POST['username']; $password=$_POST['password']; if(empty($username) && empty($password)) { echo"<script>alert('please enter username and password')</script>"; } if(empty($username) || empty($password)) { echo"<script>alert('please enter username and password')</script>"; } $pass= hash('sha512', $password); $set="Lecturer"; $set2='Admin'; $sel="select * from $tb1 where username='$username' and password='$pass'"; $result=mysqli_query($con,$sel); $row=mysqli_fetch_array($result); if($row['username']== $username && $row['password']== $pass && $row['usertype']==$set) { $_SESSION["username"] = $_POST["username"]; $_SESSION['last_login_timestamp'] = time(); $_SESSION['username'] = $username; header('location:userhome.php'); } elseif ($row['username']== $username && $row['password']== $pass && $row['usertype']==$set2) { $_SESSION["username"] = $_POST["username"]; $_SESSION['last_login_timestamp'] = time(); $_SESSION['username'] = $username; header('location:adminhome.php'); }} else {echo"<script>alert('not registered/approved')</script>";} ?>
I have two files with coding in. One of them is the HTML form file: Code: [Select] <?php <html><head><title>Car Accident Program</title></head> <body> <!----In this block of code I am creating a form with 4 text boxes and a button as well as user prompts to get user inputted values to work with----> <h4>Car Accident Report Form</h4> <form action="Car.php" method="post"> <b>First Name:<b><br> <input type="text" size = "45" name="firstname"><br> <b>Surname:<b><br> <input type="text" size = "45" name="surname"><br> <b>Age:<b><br> <input type="text" size = "45" name="age"><br> <b>Number of weeks since accident:<b><br> <input type="text" size = "45" name="weeks"><br> <input type="submit" value="Submit report"> </form> </body> </html> and the PHP/Validation file: Code: [Select] <!----In this block of code, I am creating a PHP script that gets the user inputted values and can display them in a report as well as use an IF statement to show an extra line to appear if the user enters an age below 18 or a time since accident below 1 week or if they miss out a field or more----> <?php $firstname= $_POST ['firstname']; $surname =$_POST ['surname']; $age=$_POST ['age']; $weeks=$_POST ['weeks']; //Here, I am providing various paths and the outcomes in a PHP script if (empty($_POST['firstname']) or empty($_POST['surname']) or empty($_POST['age']) or empty($_POST['weeks'])) {$msg= "You missed out one or more fields. Click on the link below to go back to the form and enter information into all of the fields";} else if (is_numeric($age) && $age<0) {$msg="You cannot be under 0 years of age";} else if (is_numeric($weeks) && $weeks<0) {$msg="The number of weeks since an accident cannot be below 0";} else if (is_numeric($age) && $age>0 && $age<18) {$msg= "You are too young to file an accident report";} else if (is_numeric($weeks) && $weeks<2) {$msg= "You cannot file an accident report that happened less than two weeks ago";} else { setcookie(" $msg= "First Name: $firstname<br>"; $msg .="Surname: $surname<br>"; $msg .= "Age: $age<br>"; $msg .="Number of weeks since accident: $weeks<br>"; $msg .="Your report has been accepted. Please click on the link below to go back to the Accident Report Page";} echo ($msg) ?> </body> </html> <html> <a href="http://localhost/Car.htm"><br><br>Click here to add/edit an Accident Report</a> I was wondering how, if suitable, I would add a cookie or session into coding like this. Any help is appreciated, Andrew I am using the ReactPHP event loop with periodic timer. The code works but the browser always shows that the activity is going on (the circle on the chrome tab is always running, refer the link to image below) and it runs only once. Is it possible to get rid of the running circle and still the periodic loop should run in loop at given intervals to execute the code within the loop. Please advise. Circle on the tab Below is my code, Note: **getAll($temp) is a function with parameter in another .php file. I have got the file as include in my current .php file.
$Loop=React\EventLoop\Factory::create(); $Loop->addPeriodicTimer(5, function(React\EventLoop\TimerInterface $timer) use(&$temp, $Loop, &$Total) { try{ $Total = getAll($temp); echo"<script>document.getElementById('Overall').innerText=".$Total."</script>"; }catch (Exception $e){ echo "Error in Loop"; throw $e; } }); I was going to use Google analytics API to develop my cms dashboard content but i am unsure that it's the best way to go about it. Does anyone have any suggestions? Hi
Could you please tell me how can i implement gmail api to send email to user contact on behalf of that user.
hi phpfreaks I have an class that is called "connDatabase" what I want to do with it is either extend it or implement it. But I don't know which one to use. The other issue I have is say class "a" has three vars that the that the construct needs to obstantiate and "connDatabase" needs three of its own. How do I obstantiate? thanks for any help I just posted a topic on here about sorting php array alphabetically, the solution was posted so quick I decided to post this as well and maybe save some of my time. So I have this javascript Quote <html> <head><title>Darkapec Movie Player</title> <script type="text/javascript" src="ss1.js"> </script> </head> <body> <h1>Darkapec Movie Player</h1> <b>Video location :</b> <input type="text" id="id4"/> <input type="button" onclick='ld()' value="Load" /><br/> <div id="id1"></div> <div id="nowt"></div> <script type="text/javascript"> function ld(){ document.write("<html><!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN\"http\:\/\/www.w3.org\/TR\/html4\/loose.dtd><html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" xml:lang=\"en\" lang=\"en\"><head><title>Darkapec Movie Player</title><script type=\"text\/javascript\" src=\"ss1.js\"><\/script><script type=\"text\/javascript\" src=\"fun1.js\"><\/script><\/head><body><h1>Darkapec Movie Player<\/h1><br/><embed type=\"application/x-vlc-plugin\" name=\"video1\" id=\"vlc\" autoplay=\"yes\" loop=\"no\" width=\"640\" height=\"480\" target=\""+document.getElementById("id4").value+"\"/><div id=\"nowt\"></div><div id=\"id1\"></div><div id=\"id2\"></div><script type=\"text\/javascript\" src=\"fun1.js\"><\/script><br/><input type=\"button\" onclick='pl()' value=\"Play\" /><input type=\"button\" onclick=\'ps()\' value=\"Pause\" /><input type=\"button\" onclick=\'st()\' value=\"Stop\" /><input type=\"button\" onclick=\'vlc.audio.toggleMute()\' value=\"Mute\" /><br/><b>width :</b><input type=\"text\" id=\"i1\"/><br/><b>height :</b><input type=\"text\" id=\"i2\"/><br/><input type=\"button\" onclick=\'aspectRatio()\' value=\"Adjust Screen\" />"); } </script> <br/> </body> </html> I have put 2 enclosing the code where I would like to implement the following PHP script Quote <?php $dir="/backup/Movies"; $files = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php" && $file != "New Movies" && $file != "Icons" && $file != "Tv Shows") { $files[] = $file; } } closedir($handle); } sort($files) ?> <form action="listen.php" method="post" name="table"> <select name="Movie"> <p> <?php $tmp = array(); foreach ($files as $file) { $tmp[] = "<option value='$file'>$file</option>"; } echo implode("\n",$tmp) . "\n"; ?> </p> </select> </form> Thanks again for the help Jake Hi All,
How could i implemnent tab strip (jquery ui tab) in php.
Any help in this regard will be appreciated
Thanks
Ahsan
I have a while loop that fetches data from the database and prints it out organized in a table. Now I want to implement a voting functionality, the problem I'm encountering is, once I've printed out a list of tables one table after other with the while loop I need to figure out a way to tell the query TO WHICH of those tables to ADD or SUBTRACT the vote. I thought of implement a hidden id field into the while loop of contributions, the id field would be fetched from the auto_increment field in the contribution table in the MySQL database. Since the id field is unique there can be no misunderstandings to which table to add the vote. My question how can I do exactly that? How can I add a hidden id field to the while loop with the table WHICH I then can pass along to the voting script. Here's the while loop: while ($row = mysqli_fetch_array($data)) { echo "<table padding='0' margin='0' class='knuffixTable'>"; echo "<tr><td width='65px' height='64px' class='avatar_bg' rowspan='2' colpan='2'><img src='$avatar_path' alt='avatar' /></td><td class='knuffix_username'><strong>" . $user_name; echo "</strong><br />" . $row['category'] . " | " . date('M d, Y', strtotime($row['contributed_date'])) . "</td></tr><tr><td>"; echo "<form action='' method='post'> <input type='submit' name='plusVote' value='Y' /> <input type='submit' name='minusVote' value='N' /> </form></td><td class='votes'>Y[ - ] | N[ - ]</td></tr>"; echo "<tr><td class='knuffix_name' colspan='3'><strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td colspan='2' class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "</table>"; } If I simply add $row['con_id'] it's obviously going to be echo'd out, what is the right practice to have it hidden? Basically I am submitting and retrieving data from a 3rd party's API. But every time I submit a form, it gives me this error. Access to XMLHttpRequest at 'https://3rdpartywebsite.com/api' from origin 'https://mywebsite.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
So I have been researching and there seems to be so many different answers. I have tried adding this code to the page but still get an error. <?php // ADD THIS CODE ON THE VERY TOP OF THE PAGE I AM SUBMITTING THE FORM. header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Credentials: true"); header("Access-Control-Max-Age: 1000"); header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding"); header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE"); ?>
I have also tried to add this to .htaccess file and still get the same error. Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
I was wondering what am I doing wrong? What's the correct way of implementing CORS to my site? |