I am having trouble extracting the original referer in my 404 error
script.
What you want is:
<?php
if (isSet ($_SERVER['HTTP_REFERER'])) {
# if (eregi (('http://' . $_SERVER['SERVER_NAME']), $_SERVER['HTTP_REFERER'])) {
echo "\n<p>A message to the webmaster has just been sent automatically, to inform her/him to make arrangements$
$recipient = 'webmaster@YOUR DOMAIN';
$website_name = 'NAME OF WEBSITE';
$subject = "{$_SERVER['SERVER_NAME']} error: 404 (non-existent resource)";
$mailheaders = "From:$websiteN ame website monitor <$recipient>\n" ;
$message = "\nA 404 message was generated from someone loading a resource on {$_SERVER['SERVER_NAME']}\n\n";
$message .= " The resource is at {$_SERVER['HTTP_REFERER']}\n";
$message .= " which attempts to load http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}";
$browserDescrip tion = (isSet ($_SERVER['HTTP_USER_AGEN T']) ? $_SERVER['HTTP_USER_AGEN T'] : '');
$message .= "\n\n" . $_SERVER['REMOTE_ADDR'] . "\n" . $browserDescrip tion;
mail ($recipient, $subject, wordwrap ($message), $mailheaders);
# }
}
?>
(Sorry if the lines wrap.)
Uncomment the two lines beginning with # if you want to enable broken link
detection for referrers ONLY within your site.
Bear in mind that you will get a few spurious results due to badly
configured spambots/scumbots and all sorts of other rubbish out there. If
you get a referrer of
www.iaea.org I personally would ban that IP.
Martin Lucas-Smith
www.geog.cam.ac.uk/~mvl22 www.lucas-smith.co.uk