Automatic Copyright Year

Filed Under: PHP Stuff

PHP Solutions

Isn’t it annoying when you have five or six websites, and you have to go back into them every January 1st and update the year? Couldn’t you use that half hour or more to be doing something else? Well, sure. I have looked and I have looked over and over again, and could not find anything. Finally, I went online to FriendsOfEd and bought a book called PHP Solutions. As I was reading through this book, I realized that they had a very simple PHP script to automatically update the year on your copyright for you! The script is so easy to understand its unbelievable, and its implementation is like wow, thats it? Okay, enough blabbing, here is the code:

<?php
ini_set('date.timezone', 'US/Mountain');
$startYear = 2007;
$thisYear = date('Y');
if ($startYear == $thisYear)
{
     echo $startYear;
}
else
{
     echo "{$startYear}-{$thisYear}";
}
?>

All that you have to do is set the timezone of your region. And than the start year of your website. So, if you started it in 2005 you would change the 2007 to 2005. And than what the script tells the server to do is, check to see if the start year that you have entered matches what the server says the year is. If it does than only display the start year. If it is different, than display the start year and than a - and than the servers current year.

So, really all that it is doing is saying, “Hey server, do you have the same date as I do? No, well what do you say the date is? Okay, now display it on the screen for me.” That’s it. You now have a copyright year, that you will never have to touch again!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Technorati
  • Facebook
  • Google
  • LinkedIn
  • TwitThis
Copyright © 2007-2008 StyleYourBlog
Website Developed by Bennie Mosher
Log in