Monday, December 13, 2010

404 Trapper PHP Script download

Download 404 Trapper PHP Script

<?php
#########################################################
# 404 Trapper #
#########################################################
# This script was created by:
# PHPSelect Web Development Division. #
# 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 an .htaccess file in the document root on your web server. Insert the line: #
# ErrorDocument 404 /404trap.php #
# ..where /404trap.php reflects the path, relative to #
# your document root, where the script lives. Then configure and upload this script. #
#########################################################
# 404trap.php #
#########################################################

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

# Set $domain to your domain name (no www)
$domain = "test.com";

# Set $docroot to the URL of the directory which contains your
# .htaccess file. Don't include trailing slash.
$docroot = "http://www.test.com";

# Set $template to the full system 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 = "you@example.com";

#########################################################
# End of configuration variables #
#########################################################

# The print_details function is what prints the 404 error to
# the visitor.

function print_details(){
# Request access to the global variables we need
global $docroot, $reportlevel;

# Print the 404 error in web format
$output .= <<<EOT
<b><h1>404 Not Found</h1></b>
<p><font face="Verdana, Arial" size="2">
We're sorry. The page you requested, $docroot$_SERVER[REQUEST_URI], doesn't exist
on this server.</font></p>
EOT;

# If an email report is being generated, let the visitor know:
if ($reportlevel != 0){
$output .= <<<EOT
<p><font face="Verdana, Arial" size="2">The details of this error have automatically
been mailed to the webmaster.
EOT;
}
if($template){
$template = implode("", file($template));
$template = str_replace("%OUTPUT%", $output, $template);
echo $template;
}
else{
echo $output;
}
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 $emailaddress, $docroot;

# Build the $errortime variable to contain the date/time of the error.
$errortime = date("d M Y h:i:s");

# Create the body of the email message
$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";

# Send the mail message. This assumes mail() will work on your system!
$headers = "From: $emailaddress\nDate: $errortime -0600\n";
$subject = "404 Error: $docroot$_SERVER[REQUEST_URI]";
mail($emailaddress, $subject, $message, $headers);

return;
}
header("404 Not Found");
# 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.
switch($reportlevel){
case 0:
break;
case 1:
if(eregi($domain, $_SERVER[HTTP_REFERER])){
send_email();
}
break;
case 2:
send_email();
break;
}
?>

By PHP with No comments

0 comments:

Post a Comment

    • Popular
    • Categories
    • Archives