
11/082013
So you’ve started to get how HTML works, and by now you’ve been building a bunch of HTML static websites. It’s been an year since you started and now you just realized that all your footers display as copyright information an outdated year:
Copyright © 2011-2012 Connictech.com
You know you have to update the text in all your footers, but you are already thinking about creating a dynamic footer with copyright information that is always up to date. Here’s the PHP code that you will have to insert in your HTML files:
<div id="footer">
<p>©
<?php
ini_set('date.timezone', 'America/New_York');
$startyear = 2011;
$thisyear = date ('Y');
if ($startyear == $thisyear)
{echo $startyear;}
else { echo"$startyear-$thisyear";}
?>
Connictech.com</p>
</div>
The PHP code above calculates the current year and stores it in the $thisyear variable, checks whether it’s different from a fixed year (stored in the &startyear variable), and displays the appropriate years in the copyright statement. Once you copy the php file on your server the output sent to your browser by PHP will be:
Copyright © 2011-2013 Connictech.com
There are easier and shorter ways to do this, but this version will also work in the first year that you launch your website.
In this case the HTML output will be:
Copyright © 2013 Connictech.com
Did you think you would have to update all your footers every year? Not when you use php to create dynamic copyright statements.
Leave comment