Make Your Copyright Notice Dynamic

Most website and blog owners place some kind of copyright information on their websites and in their blogs. Copyright notices mean that the copyright holder, reserves all the rights provided by copyright law, such as distribution, performance, and creation of derivative works.

Copyrights are usually found in the footer of most designs, themes or templates. My copyright information is found in the footer. It says, “Copyright © 2003-2011. All rights reserved.” The copyright notice will need to be updated yearly to reflect the current year.

Some owners place a range of years, such as 2000-2010, just like mine, to reflect that the website or blog has been around for a number of years. Often times, the owner forgets to update the copyright information. It’s a simple text change, but there are ways to make it dynamic.

By making your copyright notice dynamic means you never have to edit the copyright notice ever again. At every New Year’s eve, while you are out celebrating, your website magically updates the copyright notice to the latest year. How? It uses a PHP function called date().

To get the current year, use the PHP date function:

<? echo date(“Y”); ?>

If you want a range of years, you can use:

2001-<? echo date(“Y”); ?>

There you have it, a dynamic copyright notice! And one more thing, to display the copyright symbol properly, use the HTML special symbol:

&copy; or &#169; which are the same as the symbol ©

PHP Time of Day Script

One very cool way of taking advantage of PHP’s powerful language is to make a determination as to what time of the day it is, and making a decision based on that information. For example, we want to detect the server’s current time and display a message that says either good morning, good afternoon or good evening.

There’s a handy PHP function called date that we can use. We can assign a variable called $current_time, to the server’s current time.

$current_time = date(G);

Next, let’s display the logic.

if ($current_time >= 0 && $current_time < 12) { echo 'Good Morning';}
if ($current_time >= 12 && $current_time < 18) { echo 'Good Afternoon';}
if ($current_time >= 18 && $current_time < 24) { echo 'Good Evening';}

You can also display images based on time of day.

if ($current_time >= 18 && $current_time < 24) { echo<img src=”sample.jpg” />;}

HTTP Referrer

This short article will teach you how to return your program to the referring URL if you are running a PHP script or a function. At the top of the script you will need to capture the referring URL by including the following:

$ref = getenv("HTTP_REFERER");

You can then place your function next anyway you want it.

function {
 your function ...

When you are done, you can return the user to the referring URL by sending a header function.

header('Location: '. $ref );

Caveat: you will get a “header already sent error” if you are printing to the screen before the header function.

That’s it.