Location: PHPKode > scripts > 404 Catcher PHP Script > 404-catcher-php-script/404info.php
<?php
##########################################################
#                     404 Catcher                        #
##########################################################
#                                                        #
# This script is copyright 2009 SEO-Shop.com             #
#                                                        #
# You are granted full rights to use this script on any  #
# site you own. However, redistribution of this script   #
# REQUIRES that this copyright notice remain in place.   #
#                                                        #
# HOW TO USE THIS SCRIPT:                                #
# Create or edit .htaccess file in the document root     #
# on your web server. Insert the following line:         #
# ErrorDocument 404 404info.php                          #
##########################################################


#########################################################
# Set these variables to configure the script           #
#########################################################

# Set $docroot to the URL of the directory which contains your
# .htaccess file. Don't include trailing slash.

$docroot = "http://www.seo-shop.com";

# Set $domain to your websites domain name (no www)

$domain = "seoshop.com";

# Set $template to the full SERVER path to the HTML file that
# you want to use as a template. If you don't set this, the
# script will use its default built-in template. If you create
# your own template, place the token %OUTPUT% where you want
# the output to appear.

$template = "";

# 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, just display the page
# 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.
# You can leave this unassigned if you're not using email features.

$emailaddress = "hide@address.com";

#########################################################
# End of configuration variables                        #
#########################################################
header('Cache-Control: public'); 

function send_mail(){
   global $emailaddress, $docroot;
   $errortime = date("d M Y h:i:s"); 
   $message = "404 Error Report\n\nA 404 error was encountered by $_SERVER[REMOTE_ADDR]";
   $message .= " on $errortime.\n\n";
   $message .= "The URI which generated the error is: \n$docroot$_SERVER[REQUEST_URI]\n\n";
   $message .= "The referring page was:\n$_SERVER[HTTP_REFERER]\n\n";
   $headers = "From: $emailaddress\nDate: $errortime -0600\n";
   $subject = "404 Error: $docroot$_SERVER[REQUEST_URI]";
   mail($emailaddress, $subject, $message, $headers);
   return;
}

header("Status: 404 Not Found");

$output = <<<EOT
<html>
<head> </head>
<body>
<h1>404 Not Found</h1>
 <p>
   <font face="Verdana, Helvetica, Arial" size="2">We are sorry. The page you requested, $docroot$_SERVER[REQUEST_URI], does not exist on this server. </font>
 </p> 
 <p> 
   <font face="Verdana, Helvetica, Arial" size="2">   
     The details of this error have automatically been mailed to the $domain webmaster.<br />  
  </font> 
 </p> 
 <p> 
   <font face="Verdana, Helvetica, Arial" size="2">  
     We should have this issue resolved shortly.<br />  
   </font>  
 </p>  
 <p>  
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
 </p>
EOT;

if($template){
  $template = implode("", file($template));
  $template = str_replace("%OUTPUT%", $output, $template);
  echo $template;
}
else{ echo $output; }

switch($reportlevel){
  case 0:
    break;
  case 1:
    if(eregi($domain, $_SERVER[HTTP_REFERER])){
      send_mail();
    }
    break;
  case 2:
    send_mail();
    break;
}

?>
                                                                                                                                                                                                                                                                                     
Return current item: 404 Catcher PHP Script