Jump to content

php countdown confusion


MarcP

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...