10 Jun 2009

Auto-updating year in copyright notice of website footer using PHP

Author: Adam | Filed under: PHP, Web Design

A 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:

&copy; 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!

Add This! Blinkbits Blinklist Blogmarks BlogMemes BlueDot BlogLines co.mments Connotea del.icio.us de.lirio.us Digg Diigo DZone Facebook FeedMeLinks Folkd.com Fleck Furl Google Google Reader icio.de IndianPad Leonaut LinkaGoGo Linkarena Linkter Magnolia Mister Wong MyShare Ask.com MyStuff Ask.com Yahoo! MyWeb Netscape Netvouz Newsgator Newsvine Oneview.de RawSugar reddit Rojo Segnalo Shadows Simpy SlashDot Smarking Sphere Spurl Startaid StumbleUpon TailRank Technorati ThisNext yigg.de Webnews.de ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com Plugin by Dichev.com

One Response to “Auto-updating year in copyright notice of website footer using PHP”

  1. Thank You Man i was looking for this exact piece of code for a website i’m working on..again thanks

Leave a Reply