MarcP Posted February 16, 2016 Share Posted February 16, 2016 I would like some code to countdown 10 days. At the end of 10 days the user would be redirected to a webpage. I would prefer a server side language. Can't I utilize the following code to determine the countdown starting point?? <?php $d=strtotime("+10 Days"); echo date("M-d-Y h:i:sa", $d) . "<br>"; ?> The following code works but I would prefer not to set a specific date. HERE'S THE CODE THAT I HAVE SO FAR <?php date_default_timezone_set("America/New_York"); $days = 11; // Day of the countdown $month = 2; // Month of the countdown $year = 2016; // Year of the countdown $hours = 20; // Hour of the day (east coast time) $event = "Your Trial period expires."; //event $calculation = ((mktime ($hours,0,0,$month,$days,$year) - time())/3600); $hours = (int)$calculation; $days = (int)($hours/24); if ($hours <= ("0")) { echo '<script>window.location.href = "TRIALPAGE_B.html";</script>'; } ?> <ul> <li>The date is <?=(date ("l, jS \of F Y g:i:s A"));?>.</li> <li>It is <?=$days?> days until <?=$event?>.</li> <li>It is <?=$hours?> hours until <?=$event?>.</li> </ul> Link to comment Share on other sites More sharing options...
Ingolme Posted February 17, 2016 Share Posted February 17, 2016 You can store the date produced by strtotime() in a database. When the page loads, check the database row associated with that user, if the trial end date is not there, create it using strtotime(). If it is there, then calculate the difference between then and now. Another way to do it would be to store the time the trial started, then each time you load it from the database you compare the current time with it to see if more than 10 days have passed. This way is more flexible because you can change the target time after the countdown has started. Link to comment Share on other sites More sharing options...
MarcP Posted February 17, 2016 Author Share Posted February 17, 2016 Thank You, I'm a newbie to php, can you give me an example? or point me to an example that I can look at? Link to comment Share on other sites More sharing options...
Ingolme Posted February 18, 2016 Share Posted February 18, 2016 I think if the concept is difficult to understand you still have to learn more basic things. Learn how to connect to a database and store and retrieve information from it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now