Auto-updating year in copyright notice of website footer using PHP
Author: Adam | Filed under: PHP, Web DesignA little tip for my fellow web designers. Some of you will already know how to do this, as it’s not overly complicated. However, some of you will not - for those people I hope this will be useful.
At the footer of most websites, you will have a copyright notice, along the lines of:
© Copyright 2009 TheMasterBrewer
Have you ever found it a nuisance having to update the year every January on all of your websites? I used to. But it’s actually very simple to make your websites automatically update themselves using a little nugget of PHP. Your web pages will of course have to be written in PHP if you use this method - basic HTML files (.htm or .html) or files coded in other languages (e.g. ASP, JSP, etc) won’t work.
So, what’s the code? You simply use the PHP date function to retrieve the current year. You can retrieve it in various formats, but the format we require is a four digit full numeric representation of the year. This is called using an uppercase ‘Y’. So, the code is simply:
date(’Y')
Simple, huh? You just echo this and it comes out as 2009, or whatever year it is. So, for the above copyright statement, your code would be:
© Copyright <?php echo date('Y'); ?> TheMasterBrewer
That’s it. The next time the clock strikes midnight on New Year’s Eve, all your websites will automatically update the year in their copyright notices.
Many of you will read this and think “duh”, but hopefully some of you will find it useful. If you have any questions, let me know. Cya!
4 Responses to “Auto-updating year in copyright notice of website footer using PHP”
Leave a Reply
You must be logged in to post a comment.



































































Thank You Man i was looking for this exact piece of code for a website i’m working on..again thanks
Actually this code doesn’t work, oh dear. When I copied it I got an error and that’s because one of the apostrophies is ’ while the other is ‘. You should use the second type
Oops! Thanks for pointing that out, I’ve updated the code
Thanks for the code.