I've got a script that you can try out. Essentially what you're doing is setting up an .htaccess file, that will call to a php file that contains a script. This script will then send you the information in regards to the error that was received.
I haven't used this method in awhile, since my blog relies on a Wordpress Plugin that redirects to a customized 404 report page. Anyway:
Code:
<?php
//choose the record either of the following statements
//depending on what your host provides
$file404 = $_SERVER['REDIRECT_ERROR_NOTES']."\n";
//or
$file404 = $_SERVER['REDIRECT_URL'] . "\n";
$filename = '/var/users/mysite/htdocs/history404.txt';
if (file_exists($filename))
{
$filecontents = file($filename);
$add = (!in_array($file404, $filecontents));
}
else $add = true;
if ($add)
{
$fp = fopen($filename, 'a');
$write = fputs($fp, $file404);
fclose($fp);
$body = '';
$reportvars = array('REDIRECT_ERROR_NOTES','HTTP_HOST', 'HTTP_REFERER', 'HTTP_USER_AGENT', 'HTTP_FROM',
'REDIRECT_URL', 'REDIRECT_REQUEST_METHOD', 'REDIRECT_STATUS','REQUEST_URI','QUERY_STRING',
'REMOTE_ADDR', 'REMOTE_PORT');
foreach($reportvars as $key) $body .= "$key: {$_SERVER[$key]}\n";
mail('webmaster@mysite.com','404:' . $_SERVER['REDIRECT_URL'],$body);
}
$revbits = explode('.',strrev($_SERVER['REDIRECT_URL']));
$pages['html'] = array('html','htm','php','txt');
$pages['special'] = array('css', 'js');
$ext = strrev($revbits[0]);
if (in_array($ext, $pages['html']))
{
// or show a make a comment form
header('Location: /index.php');
}
elseif (in_array($ext, $pages['special']))
{
//output nothing
echo '';
}
else
{
//throw a large image onto the screen so it's easy to hunt down.
//change the width and height to a more discreet dimension when live
//although if the img has height and width attributes that will overrule
//the width and height here
$width = 50;
$height = 50;
$image = ImageCreate($width,$height);
$blob = ImageColorAllocate($image,27,48,107);
if (function_exists("imagegif")) {
header ("Content-type: image/gif");
imagegif ($image);
}
elseif (function_exists("imagejpeg")) {
header ("Content-type: image/jpeg");
imagejpeg ($image, "", 0.5);
}
elseif (function_exists("imagepng")) {
header ("Content-type: image/png");
imagepng ($image);
}
elseif (function_exists("imagewbmp")) {
header ("Content-type: image/vnd.wap.wbmp");
imagewbmp ($image);
}
else
// or whatever action should be taken if you don't have GD installed.
die("No image support in this PHP server");
ImageDestroy($image);
}
?>
To call the scripts add the following to your .htaccess file.
ErrorDocument 404 /track.php
You can name the file anything you want, so long as it contains the above code. You also have to make sure that you add other error codes to the htaccess file, unless you ONLY want to record missing links/pages that's being picked up.