Quick PHP Tip

Quick PHP Tip

By Jacob Haug on January 26th, 2010 in Tips & Tricks

Did you remember to manually update your copyright statement to 2010? With one line of PHP all your problems can be solved!

Recently, I was reading an article on Smashing Magazine called…”Don’t Forget The Small Stuff This Year“, and within that article it reminded users to update their copyright statement each new year!

Have you ever forgotten to update your copyright statement to 2010? I know I have, however; let’s make sure that doesn’t happen again. With this short PHP code snippet, your statement will automatically update! How cool is that?

<p><strong>&amp;copy; Copyright 2010 <a href=&quot;/&quot;>The Web Squeeze, LLC.</a> All Rights Reserved.</strong></p>

We’re going to change the above to…

<p><strong>&amp;copy; Copyright <?php echo date('Y'); ?> <a href=&quot;/&quot;>The Web Squeeze, LLC.</a> All Rights Reserved.</strong></p>

The key in the above code is this line…

<?php echo date('Y'); ?>

The above line of code is using PHP’s built in date function. We’re saying echo out the current year (Y) in a 4 digit format. (e.g. 2010) If you’ve never used the date function, or want to customize the above a bit further, check out the date function.

http://us2.php.net/manual/en/function.date.php

I hope this helps make your life just a tad easier!

Did you like it? Share it!
  • Delicious
  • DesignBump
  • DesignFloat
  • Digg
  • Facebook
  • StumbleUpon
  • Technorati
  • Twitter
About The Author
Jacob Haug

My name is Jacob Haug, and I spend the majority of my time in website development. I donate many hours each day helping the web community with technical aspects of website design and development. My current project is The Web Squeeze. A “NEW”, “FRESH”, Web Design and Development community dedicated to helping make the internet a better place! @JacobHaug

Comments
  • January 26th, 2010 at 10:00 am.

    I bet you are Jacob!
    You have just reminded me to change them. I did read the same article in Smashing Magazine but somehow I did not think about it, silly me ^_^

  • January 26th, 2010 at 12:39 pm.

    Great tip! I always do this for designs since it would be a hassle to have to find each site I ever built each year, just to update that little number.

    PHP saves the day, once again! :D

  • January 26th, 2010 at 5:30 pm.

    Nice little tip, Jacob :)

    I believe technically copyright dates should be a range if they span more than one year (which they will if you’re changing the date).

    So really, your code should be more like:
    <p><strong>© Copyright 2008 – <?php echo date(‘Y’); ?> <a href=”/”>The Web Squeeze, LLC.</a> All Rights Reserved.</strong></p>

    Or something similar :)

  • January 26th, 2010 at 7:34 pm.

    I saw people do like that. What is the different between that two?
    Which is the best or should I say, which one should we use?

  • January 27th, 2010 at 4:02 pm.

    I wasn’t aware of this tip but this would certainly come in handy. I’m going to implement this on my client sites. I use a span of years in copyrights so Japh’s code will work well for the majority. However when I develop a brand new site for a new business, Jacob’s will work for the first year!
    Thanks!

  • January 27th, 2010 at 4:07 pm.

    I wasn’t aware of this tip but this would certainly come in handy. I’m going to implement this on my client sites. I use a span of years in copyrights so Japh’s code will work well for the majority. However when I develop a brand new site for a new business, Jacob’s will work for the first year!
    Thanks!

  • January 27th, 2010 at 6:23 pm.

    Hmm… so longer-lasting code then, so you can use it on new projects too! ;)

    <p><strong>© Copyright <?php $year=’2008′; echo (date(‘Y’) == $year ? $year : $year.’ – ‘.date(‘Y’)); ?> <a href=”/”>The Web Squeeze, LLC.</a> All Rights Reserved.</strong></p>

  • Marc Fraser
    January 29th, 2010 at 6:25 am.

    I believe, from what I’ve read, that using a Copyright deceleration at the bottom of your website doesn’t matter. Anything you publish to the internet is copyright of the website, regardless of whether you have this deceleration or not. A Copyright deceleration, however, is useful if you are displaying another person’s work on your website.

    Disclaimer:
    Please remember, that in no way am I an IP (Intellectual Property) lawyer. Thus, accept no liability for the above statement.

  • February 1st, 2010 at 9:39 am.

    @Japh @Linda

    It’s all a matter of personal preference which you use. It’s not required to use a range, however, some prefer that.

    @Marc

    That’s a good point Marc!

    The humble copyright notice is always useful to show in the footer, as a way of stating your claim over a site. Interestingly, however, it is not required for you to have copyright over the graphics, content and artwork of your site. This comes into place as soon as you’ve created the content and placed it in the public domain. Placing a copyright notice is still advisable to deter potential plagiarists and stake your claim.

So, what do you think?

x