[thelist] Smart 404 tracing for stooges and PHP

John C Bullas jcbullas at nildram.co.uk
Sat Sep 27 01:47:08 CDT 2003

I am not a good programmer or scripter!!!!!

I had a lot of 404 hits showing when I loaded my weblogs into WEBlog Expert 
(free trial)

I then was given a PHP script to send me an email when the 404 error 
occurred (my webspace included PHP support)

I just renamed my 404 page in the .htaccess file as 404.php and changed

ErrorDocument 404 http://www.ime.org.uk/404/404.html


ErrorDocument 404 /404/404.php

so the 404s showed properly  ;) .......


soon discovered the webcrawlers idea of what they thought my site looked 
like (the new site has redirects from 2 previous
guises and some of the redirects were hitting the wrong sub-directories etc 
etc etc

Also soon saw the main culprits for links to my sites where they had put in 
the wrong URL!!!!! it emails me the
URL they typed or followed in AND where they came from!!!!!

=========== Sample ===============

Sat Sep 27 2003 7:41:51 am BST tried to load www.ime.org.uk/missing.shtml

User Agent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 

Referring URL:



If you are ever bored and want something to do.... set up a smart 404 page!!!

You might need to blackhole the virus triggered sweeps of your cgi-bin 


============= PHP script ==============


$ip = getenv ("REMOTE_ADDR");

$requri = getenv ("REQUEST_URI");
$servname = getenv ("SERVER_NAME");
$combine = $ip . " tried to load " . $servname . $requri ;

$httpref = getenv ("HTTP_REFERER");
$httpagent = getenv ("HTTP_USER_AGENT");

$today = date("D M j Y g:i:s a T");
$message = "The Webmaster has been informed that:<br>On $today,  \n
$combine <br> \n
User Agent = $httpagent <br>\n
Referring URL (if any) : $httpref";

$note = "Referring URL:" ;

$message2 = "$today \n
$combine \n
User Agent = $httpagent \n
$note \n
$httpref ";

$to = "something at somewhere";
$subject = "404 recorded at lalalal.org";
$from = "From: r17 at isp.co.uk\r\n";

mail($to, $subject, $message2, $from);

echo $message;

More information about the thelist mailing list