Quantcast
Channel: Brian P Jones » Web
Viewing all articles
Browse latest Browse all 2

Keep Your Copyright Current Dynamically with PHP and ASP

$
0
0

It’s a small detail, but one of my pet peeves — an expired copyright notice. I’ve been guilty of this myself. The fact of the matter is that having an old copyright date reflects poorly on your website, and ultimately your product or service. The problem is that many sites — even those built dynamically — use plain html text to display their copyright. It then becomes an easy thing to overlook or push aside at the turn of a new year. So, why not write these few lines of code and never worry about changing your copyright notice again?

 

For pages built with PHP, here is a snippet of code that you can modify and use to suit your needs:

 

<?php
date_default_timezone_set('America/Los_Angeles');// set your default timezone if site is hosted in a different timezone
$now = date(Y);// The current year
$created = 2011; // The year your site was created
if ($now > $created) {
echo '&copy; ' . $created . '-' . $now . ' Brian Jones | All Rights Reserved';// prints a date range if site was created before current year
} else {
echo '&copy; ' . $created . ' Brian Jones | All Rights Reserved';// Only prints created year if same as current year
}
?>

 

The above script will print “© 2011-2012 Brian Jones | All Rights Reserved“.

 

As noted, there are a few key features of this script that make it useful.  It sets the default timezone to your location, rather than the location of the server where the file is hosted (for individuals that spend New Year’s Eve monitoring copyright dates). Secondly,  if your site was created in the current year, it will automatically create a date range when the year turns (2011-2012). Finally, your name or company is conveniently located in the echo statement.

 

I wrote the PHP script based on an ASP example I found on Codefixer. If you’re using ASP, consider this code:

 

<%
Function DynamicCopyrightYear(YearSiteCreated)
If Year(Now) > YearSiteCreated Then
DynamicCopyrightYear = YearSiteCreated & "-" & Year(Now)
Else
DynamicCopyrightYear = YearSiteCreated
End If
End Function
%> 

Copyright &copy; <%= DynamicCopyrightYear(2000) %>. All rights reserved.

That’s it! Adding a dynamic copyright notice to your website ensures your copyright notice will always be valid.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images