Computer Help Community

Community

Cyber Tech Help Community

New Tutorials

PC Tutorials

New Downloads

More Downloads
PC Downloads

Member Testimonials

Open Member Quote   Most sites are so over most people's heads and not at all people friendly. This site rocks - Carolina_Stardu  Close Member Quote
Member Testimonials
MY CYBER TECH HELP

LATEST TOPICS

Tech Help Community

Free Antivirus Scan

Free Virus Scan and a listing of the top 10 viruses in the wild - Free Antivirus Scan
Free Online Antivirus Scan

File Extension Database

Find what program a filetype belongs to in our searchable File Extension Database.
File Extension Database

Related Microsoft Links

Services
Cyber Tech Help Community

To the top of the page to top

 



Tutorials | Automatic Dead Link Reporting

Publish date: 19:01 Thursday, 28th July 2005
Written by: Steven Bentley
Audience intended for: Web Designers
Category: Web Design

Go up a levelGo up a level

Here's a sneaky way to make maintaining links in your site a little easier. This is a script that you can use as a custom 404 Not Found page that will email you with details every time somebody clicks a link on any site to a non-existant page on your site, so that you can fix the link if it's one of your own, or so that you can e-mail the developer of any other site that links to you to let them know that they have a duff link.

The code can determine between someone clicking a link and a URL that's been typed in by hand, and will provide a different error message in each case. You only get mailed when a link has been clicked. The e-mails all come with the same subject, so you can use your mail client's rules to direct them to a seperate folder if you wish.

This code uses PHP, so you'll need PHP on the server to be able to run it. The bits in bold are the sections that you need to change to customise the script for your site. You'll also need to be able to set up a custom 404 Not Found error page, something which isn't possible on every server.

Code:


<?
header("HTTP 1.0/404 Not Found");
?>
<html>
<head>
<title>
404 Not Found
</title>
</head>
<body bgcolor="white">
<font face=verdana,arial,helvetica>

<h1>404 Not Found</h1>

<?

if ($HTTP_REFERER){
echo("<p>The link you followed at <b>$HTTP_REFERER</b> was not valid.<br>This has automatically been reported to this site's maintainer who will endeavour to rectify this error as soon as possible.</p>");
echo("<p>Please <a href='$HTTP_REFERER'>Click here to return</a> or <a href='http://www.example.com'>Click here to go to this site's home page</a></p>");

mail ("youraddress@yourdomain.com","Dead Link Report","Hello,\nA user has come across a dead link to $REQUEST_URI at $HTTP_REFERER");
}else{
echo("<p>The page you requested, <b>$REQUEST_URI</b> does not exist on this server.</p>");

echo("<p>Please bear in mind that URLs on this server are case sensitive.</p>");
}
?>
</body>
</html>

Put that code into a file called 404.php and upload it to your server. Make a note of the 404.php page's location on the server. Now we need to set up the 404.php file as the custom error page, and we do that using a .htaccess file.

Open Notepad or a similar text editor and type this line:

Code:


ErrorDocument 404 path

The path bit needs to be replaced with the path from the root of the server to wherever you uploaded the 404 page to. If you put it at http://www.yoursite.com/404.php then the path is /404.php, if it's at http://www.yourwebprovider.com/yourusername/404.php then the path is /yourusername/404.php.

Save the Notepad file as htaccess.txt and upload it. It's best to put it as high up the directory structure of the server as you can, so put it at http://www.yoursite.com/htaccess.txt or http://www.yourwebprovider.com/yourusername/htaccess.txt - it will only have any effect on the directory it's in and any subdirectories. Put it at the root of the server and it will cover the whole server.

Now rename the file from htaccess.txt to .htaccess - that dot is important.

Now we're ready to test it out. Start by typing an address into the browser which does not exist, to confirm that you get the 404 Not Found page. if you don't, go back and check the .htaccess file has the correct path and has been properly uploaded. If you're sure that it's properly set up then the chances are that the server doesn't support Custom Error pages.

Make a page with a link to a non existant address on your site and upload that to anywhere you like. When you click the link you should be taken to a 404 page telling you that you clicked a bad link. You will eventually get an email telling you that a user has hit a bad link, although some servers, particularly free ones, can take a ridiculous length of time to send mail from the web out.

 

Please Note: if you have any questions about this tutorial please ask on our support forums
If you have written a tutorial of your own and would like to have it here on Cyber Tech Help all you have to do is Submit your tutorial and it will be reviewed by the Administrator.