Is it yet: PHP app
Yeasterday, I was playing around with PHP and for the sake of making somthing I made a simple ‘Is it yet” application with a countdown of days until the selected event. If you don’t understand what this does I have included a screenshot.
Want code?
Whats the event?
Use this variable to set the name of the event you are waiting for, it has to be included at the top for the <title>.
<?php<br /> # Set what you're counting down to.<br /> $eventname = &quot;Odin's birthday&quot;;<br /> ?>
Doc type and the head
This section handles the doc type, CSS and the <title> is called in from the $eventname variable with PHP.
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;<br />
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;><br />
<html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;><br />
<head><br />
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;/><br />
<title>Is It <?php echo $eventname ?> Yet?</title><br />
<style type=&quot;text/css&quot;><br />
*{margin:0px;}<br />
html{font-size:62.5%;} /* Setting the font size to 62.5% means that 1em = 10px, 1.2em = 12px and so on. */<br />
body {color:#111;background-color:#eee;}<br />
h1, h2, h3 {font-weight:bold;letter-spacing:-1px;font-family:Helvetica, sans-serif;text-align: center}<br />
h1 {font-size:22em;padding-top:30px;}<br />
h2 {font-size:3em;margin-top:150px;}<br />
h3 {font-size:2.5em;}<br />
</style><br />
</head>
Calculations, config and the rest
The last part of the file is where everything happens. The date of the event is set first, next a calculation is down to work out how many days are left, this is done with mktime but leaves us with a problem. If we set the days left to an integer, every time a day gets less than .5 php will round it down and the timer will be out. So we have to leave the value as a float and use some IF ELSE statements to sort it out later. The next bit of code controls the YES/NO function of the app, basically if the current date is equal to the date previously set then display YES else display NO. Below that is the display of how many days are remaining untill the event and also makes up for the integer problem. The code is pretty simple to read through ill let you have a look through. The last line of php just inserts the exact number of days remaining in a comment.
<body><br />
<h2>Is it <?php echo $eventname ?> yet?</h2><br />
<h1><?php</p>
<p># Set date to count down to.<br />
$day = 07; # eg. 07<br />
$month = 06; # eg. 06<br />
$year = 2009; # eg. 2009</p>
<p># Calculation for days left.<br />
$days = ((mktime (0,0,0,$month,$day,$year) - time())/86400);</p>
<p># Is it yet?<br />
if (date(&quot;jnY&quot;) == ($day . $month . $year)) {<br />
echo &quot;YES&quot;;<br />
} else {<br />
echo &quot;NO&quot;;<br />
}<br />
?></h1><br />
<h3>It's <?php<br />
# Display how many days left.<br />
if ($days <= -1) {<br />
echo &quot; over. It was &quot;;<br />
} elseif ($days <= 0){<br />
echo &quot; &quot;;<br />
} elseif ($days <= 1){<br />
echo &quot;1 day until &quot;;<br />
} else {<br />
echo (int)$days + 1 . &quot; days until &quot;;<br />
}<br />
echo $eventname;<br />
?></h3><br />
<!--Exact days left: <?php echo $days ?>--><br />
</body><br />
</html><br />
<!-- == www.twe4ked.com == -->
What else?
Server time
This script will grab the time from the server it is hosted on, not the users local time. I think JS would need to be implimented to get the script to use the local users time but thats not for me to get into.
Download
4kb






Good work, it would be nice if you could select the accuracy, like 1 day, 6 hours and 23 minutes until…