Tuesday, April 15, 2014

Autogenerate footer year with PHP

Use this php code at the footer of your website to ensure your footer PHP date is always at the current year.
You need PHP web page not static HTML. If your server handles PHP, then use the code below to insert into your website’s footer. Note this will only work with PHP web pages not static HTML.

Current Year Display

This pulls in the current date using server technology, and is really easy to implement instead of manually typing the year every year.
&copy; <?php echo date("Y"); ?> Copyright. 
displayed: © 2014 Copyright.

Website Start and Current Year

Here you set the date your website was launched, and let the PHP automatically keep the current year up to date.
&copy; <?php
$copyYear = 2008; // Set your website start date
$curYear = date('Y'); // Keeps the second year updated
echo $copyYear . (($copyYear != $curYear) ? '-' . $curYear : '');
?> Copyright. 
displayed: © 2008-2014 Copyright.