DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

PHP Copyright Updater

03.09.2007
| 6463 views |
  • submit to reddit
        // 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 © $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

Snippets Manager replied on Tue, 2007/03/13 - 10:24pm

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).

Snippets Manager replied on Tue, 2007/03/13 - 9:45pm

couldnt you just call the date() function alone for example echo "&copy " . date('Y') . " company"; and it would update on its own