Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

PHP Copyright Updater (See related posts)

// PHP Copyright Updater
// by Evan Walsh
// NothingConcept.com

This code will automatically change the copyright on your site as the year changes. Tested and approved by me.

Just call this in one of your PHP files by including the file with this code in it:

<?php
//Licensed under the GPL v2
//by Evan Walsh of nothingconcept.com
function copyright($site,$year) {
    $current = date(Y);
    if($year == $current) { $eyear = $year; }
    else { $eyear = "$year - $current"; }
    echo "All content &copy; $eyear $site";
}
?>


Example: <?php include('functions.php'); ?>

Then place <?php copyright("Sitename","2007"); ?> or something similar in the place you want the copyright to display.

Simple as that.

Comments on this post

bedodson posts on Mar 13, 2007 at 21:49
couldnt you just call the date() function alone for example

echo "&copy " . date('Y') . " company";

and it would update on its own
sk89q posts on Mar 13, 2007 at 22:29
Using "Y" as a constant is a very bad programming practice.

Here's a quicker version below. It's under public domain, because copyrighting something such as this is utterly useless.

<?php echo ($cr_start = 1996) != ($cr_end = date("Y")) ? "$cr_start - $cr_end" : $cr_end ?>


Just change 1996 to the year you need.
$cr_end
isn't truly needed, but it halves the execution time (not that it should even be a factor).

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts