ITT #2: Automate Your Copyright Years

Deal with Copyright Notices the Easy Way!

Keep Your Copyright Up-to-Date Automatically!

If you've built blogs for clients before, or created a site based on a content management system, then you know keeping copyright information up-to-date can be a pain.

It used to be that every year, I'd have to pull up every single client's site and edit the year, which would eat up a full day of my time. It was a terrible way to start the new year, and after a couple years of tedium, I decided to deal with it once and for all.

View the Demo | Download Source

Automatically Update the Year

My first instinct was to simply use PHP's handy date() and time() functions to automatically find the year. To get the current year, you can use this snippet of code:

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

This prints the current four-digit year. This technique wasn't enough, however. On websites, you need to keep the original year of the site's creation in order to cover the original content. So we need to have a range (i.e. 2006-2009).

Keep the Original Year Displayed

So we don't lose the original year, it would make sense to simply add the original posted year to the script, like so:

2006-<?php echo date('Y',time()); ?>

Now that looks great! However, what happens for new sites? We'll end up with a copyright notice for the first year that reads "All Content Copyright © 2009-2009 Company Name". This obviously isn't what we want.

Combine Both Ideas

To solve this issue, I wrote a quick function to check if the current year matches the creation year of the site, then outputs the copyright date appropriately.

<?php
  function copyrightYear($created) {
    $current = date('Y',time());
    return ($current > $created) ? $created.'-'.$current : $current;
  }
?>

<span>All Content &copy; <?php echo copyrightYear(2008); ?> Client Name</span>

Hey presto! Now, for every site we create from this point forward, copyrightYear() will output the correct year or year range for your copyright notice, and you don't ever have to worry about it again!

View the Demo | Download Source

Moving Forward

Do you have any time-saving tips for me? How about time-consuming tasks you wish you could automate? I'm looking for ideas for further Instant Tip Tuesday posts! Let me know in the comments!

Posted Feb 10, 2009 by Jason Lengstorf.
This entry is filed under instant tip tuesday, php, and copyright.

Want more content like this? Subscribe for FREE!

Comments for This Entry

GravatarAmelia02:19PM on February 10, 2009

Hey, just wanted to say thanks for this. Little thing that will save loads of time. Very cool.

GravatarBrenelz03:26PM on February 10, 2009

Nice post! Definately will be using this on future projects

GravatarThomas J. Brown05:49PM on February 18, 2009

I'm not a lawyer, but I play one on T.V.

Wait, that's not right.

Oh yeah: I'm not a lawyer, but I did take a media law class as part of my college degree and we talked a lot about copyright law.

You said, "on websites, you need to keep the original year of the site's creation in order to cover the original content." But so far as I learned, that's not true. In fact, you don't even need to slap the copyright symbol on anything you create in order to copyright it.

Copyright law states that, as soon as you create something, you own the copyright. Build a website? You own the copyright. Snap a photo on your friend's camera? You own the copyright. Draw a little doodle on the back page of your in-flight magazine? You own the copyright. This comment I've written? I own the copyright and give you permission to publish it on your site. -)

Note that this only applies to things you create. You can't copyright an idea (that's what patents are for).

GravatarJason Lengstorf06:49PM on February 18, 2009

@Thomas J. Brown:
Hmmm...

I found conflicting information online, so I figured it's better to be safe and post the copyright just in case.

It's comforting to know that I'm not giving away content if I don't post a copyright notice on it, though.

Thanks for the heads up!

GravatarThomas J. Brown07:03PM on February 18, 2009

No problem.

And like I said, I'm not a lawyer, and it was just one class, so I could be wrong. Web stuff is... Tricky at best.

All that said, it's still a really good tutorial and I'll probably make use of it in the future.

GravatarWellington04:30AM on September 21, 2009


/**
* show_year_copyright()
*
* Print the year of copyright of web application
*
* @param integer
* @return void
* @author Wellington Rodrigues
* @version 1.0
* @see 2009
*/
function show_year_copyright( $year = null )
{
date_default_timezone_set ( 'America/Sao_Paulo');
$year = preg_replace('/[^0-9]/', '', $year);
if(!$year)
{
$year = date('Y', strtotime('now'));
}
printf('%d', $year );
}

GravatarGify05:49AM on November 11, 2009

Hi Jason,
Thanks for the script will try it on my website :)
Regards,
Janet Gify

Post a Comment

Want to show your face? Get a gravatar!

ALLOWED TAGS: <tt><strong><em>