Filed under: PHP

Back Link

Do people really click on their browser’s back icon? Yes, they probably do. Would adding a link that brings a user back to the previous page a smart idea? Yes, maybe it is a smart idea. The reason is because in most occasion the user’s mouse pointer would usually be around the area of the page but not at the top left hand corner of the browser. Therefore, a back link on the page makes going back to the previous page much easier. Below is a short code snippet that I have been using if I am to write a PHP script on my own and I think it is very effective.

if (isset($HTTP_REFERER)) {
echo “<a href=’$HTTP_REFERER’>Back</a>”;
} else {
echo “<a href=’javascript:history.back()’>Back</a>”;
}

The above PHP code basically says that if the predefined variable HTTP_REFERER is set, then print a back link to the previous page, else use the java script method history.back(). Simple as that and it is fun.

Leave a Comment May 9, 2006


 

February 2012
M T W T F S S
« Mar    
 12345
6789101112
13141516171819
20212223242526
272829  

Pages

Blogroll

Categories