If you want to see the output from the script goto www.pigmaster.co.uk/444.htm by typing it in directly to the browser address bar. This will produce the 404 error message
The script is
<?
Set these variables to configure the script:
Set $domain to your domain name (no www)
$domain = "pigmaster.co.uk";
Set $docroot to the URL of the directory which contains your .htaccess file. Don't include trailing slash.
$docroot = "http://www.pigmaster.co.uk";
Font face you'd like to use on the 404 page
$fontface = "Verdana";
Font size you'd like to use on the 404 page
$fontsize = "2";
Background color of the 404 page (default is white)
$bgcolor = "#ffffff";
Text color you'd like to use on the 404 page (default is black)
$textcolor = "#000000";
This script is capable of mailing the details of each 404 error
to the webmaster. Use the $reportlevel variable to control when
you receive these reports.
#
0 = don't use the email capabilities at all
1 = send email only if the error's referer contains your domain name
(i.e. the 404 was generated by a broken link on your site)
2 = send email any time a 404 error is generated (useful for tracking
broken links at other sites which link to you)
$reportlevel = 2;
Set $emailaddress to the email address of whoever should be
notified of 404 errors. Don't escape the @ symbol. This will also
be used as the "from" address on any emails the script generates.
You can leave this unassigned if you're not using email features.
$emailaddress = "me@mydomain.com";
If you want the error message to contain a mailto: link to the
webmaster, set this variable to 1. The email address is specified
in the variable $webmasteraddress (see below).
#
0 = no link
1 = display link
$webmasterlink = 0;
Set $webmasteraddress to the email address you want displayed on
the error page. Don't escape the @ symbol.
$webmasteraddress = "webmaster@pigmaster.co.uk";
################################################################
DON'T EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING
################################################################
If you want to edit the script, I've commented profusely 🙂
################################################################
The print_details function is what prints the 404 error to
the visitor. As far as I know, PHP3 doesn't incorporate Perl's
print <<"EOT" ability. PHP4 does allow this capability
but the script was written for PHP3. So, you have to use
a lot of echo statements if you want to retain PHP3 compat.
function print_details()
{
Request access to the global variables we need
global $fontface, $fontsize, $docroot, $REQUEST_URI, $HTTP_REFERER, $emailaddress, $REMOTE_ADDR, $reportlevel;
global $bgcolor, $textcolor, $webmasterlink, $webmasteraddress;
Print the 404 error in web format
$REMOTE_ADDR=$SERVER['REMOTE_ADDR'];
$HTTP_REFERER=$SERVER['HTTP_REFERER'];
$REQUEST_URI=$_SERVER['REQUEST_URI'];
if (isset($HTTP_REFERER)) {
//show form
} else {
$HTTP_REFERER="";
}
echo "<p><font size='4' face='Verdana, Arial, Helvetica, sans-serif'><strong>404 Not Found</strong></font><p></p></p>";
echo "<p><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>The page you requested</font><p></p></p>";
echo "<p><font color='#FF0000' size='2' face='Verdana, Arial, Helvetica, sans-serif'><strong>".$docroot.$REQUEST_URI."</strong></font><p></p></p>";
if ($HTTP_REFERER != "")
{
echo "<p><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>From the link on the page</font><p></p></p>";
echo "<p><font color='#FF0000' size='2' face='Verdana, Arial, Helvetica, sans-serif'><strong>".$HTTP_REFERER."</strong></font><p></p></p>";
}
echo "<p><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>does not exist on this server.</font><p></p></p>";
If webmaster shall be displayed, generate html code
$linktext = "";
$linkclose = "";
if ($webmasterlink != 0)
{
$linktext = "<a href=\"mailto:" . $webmasteraddress . "\">";
$linkclose = "</a>";
}
If an email report is being generated, let the visitor know:
if ($reportlevel != 0)
{
echo "<p><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>The " . $linktext . "webmaster" . $linkclose . " </font>";
echo "<font size='2' face='Verdana, Arial, Helvetica, sans-serif'>has just been notified of this problem via email.</font><p><p>";
echo "<p><p><font size='3' face='Verdana, Arial, Helvetica, sans-serif'><strong>Thank You</strong></font><p>";
echo "<font size='2' face='Verdana, Arial, Helvetica, sans-serif'>Please choose a differnet link from the menu on the left or go straight to the </font>";
echo "<font size='2' face='Verdana, Arial, Helvetica, sans-serif'><strong><a href='index.htm'>Pigmaster Home Page</a></strong></font><p>";
}
return;
}
The send_email function sends the details of the 404 error to the
webmaster.
function send_email()
{
Request access to the global variables we need
global $REQUEST_URI, $HTTP_REFERER, $emailaddress, $REMOTE_ADDR, $docroot;
$REMOTE_ADDR=$SERVER['REMOTE_ADDR'];
$HTTP_REFERER=$SERVER['HTTP_REFERER'];
$REQUEST_URI=$_SERVER['REQUEST_URI'];
Build the $errortime variable to contain the date/time of the error.
$errortime = date("D M j Y G:i:s T");
Create the body of the email message
$message = "404 Error Report\n\nA 404 error was encountered by ".$REMOTE_ADDR;
$message .= " on $errortime.\n\n";
$message .= "The URI which generated the error is: \n$docroot$REQUEST_URI\n\n";
$message .= "The referring page was:\n".$HTTP_REFERER."\n\n";
Send the mail message. This assumes mail() will work on your system!
mail("$emailaddress", "404 Error Report", $message, "From: $emailaddress");
return;
}
Done with function declarations. Main function begins here.
Send a 404 error to the user's browser
print_details();
See whether or not we should send an email report. If so, do it.
if ($reportlevel != 0)
if ($reportlevel == 1) {
if (eregi($domain,$HTTP_REFERER))
send_email(); }
else
send_email();
All done!
exit;
?>