php:404 error trap and email to Administrator program _php Tutorial

Source: Internet
Author: User
# 404.php, 8/10/2000.
# Traps 404 Errors and mails a notice to the webmaster.
# Requires PHP 3.0 or newer, and mail capability on your system.
#
# Copyright Shaun@shat.net under the GNU public License.
# disclaimer:i wrote this script for me, and it works for me.
# If it doesnt work for you, or makes your server explode,
# thats life. Please email with questions or bug reports.

# Set These variables to configure the script:

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

$domain = "your.domain.com";

# Set $docroot to the URL of the directory which contains your
#. htaccess file. Dont include trailing Slash.

$docroot = "http://your.domain.com";

# Font face Youd-like-to-use on the 404 page

$fontface = "Verdana";

# Font size youd like-to-use on the 404 page

$fontsize = "2";

# Background color of the 404 page (default is white)

$bgcolor = "#ffffff";

# Text Color youd like-to-use on the 404 page (default is black)

$textcolor = "#000000";

# This script was capable of mailing the details of each 404 error
# to the webmaster. Use the $reportlevel variable-control when
# You receive these reports.
#
# 0 = dont use the e-mail capabilities at all
# 1 = Send email only if the errors Referer contains your domain name
# (i.e. the 404 is generated by a broken link on your site)
# 2 = Send email any time a 404 error was generated (useful for tracking
# broken links at other sites which link to you)

$reportlevel = 2;

# Set $emailaddress to the e-mail address of whoever should be
# Notified of 404 errors. Dont Escape the @ symbol. This would also
# be used as the ' from ' address on any emails the script generates.
# can leave this unassigned if youre not using email features.

$emailaddress = "you@your.domain.com";

################################################################
# DONT EDIT BELOW this line unless your KNOW what youre DOING #
################################################################
# If you want to edit the script, Ive commented profusely:) #
################################################################

# The Print_details function is what prints the 404 error to
# The visitor. As far as I know, PHP3 doesnt incorporate Perls
# print << "EOT" ability. PHP4 does allow this capability
# But the script is written for PHP3. So, you are
# A lot of echoes 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, $reportlevel;
Global $bgcolor, $textcolor

# Print the 404 error in Web format
echo "404 Not Found";
echo "";
echo "

404 Not Found

";
echo "

";
echo "were sorry. The page you requested, $docroot $request_uri, doesnt exist ";
echo "on the This server.

";

# If an e-mail report was being generated, let the visitor know:
if ($reportlevel! = 0)
{
echo "

";
echo "The details of this error has automatically been mailed to the webmaster.";
}

# Close up the HTML tags
# echo "";

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;

# Build The $errortime variable to contain the date/time of the error.
# Using date () likely would has been better, but I already had this code
# Elsewhere, and Im lazy.
$today = getdate ();
$month = $today [Mon];
$mday = $today [Mday];
$year = $today [year];
$hours = $today [hours];
$minutes = $today [minutes];
$errortime = "$month/$mday/$year at $hours: $minutes";

# Create The body of the email message
$message. = "404 error Reporta 404 error is encountered by $REMOTE _addr";
$message. = "on $errortime.";
$message. = "The URI which generated the error is: $docroot $request_uri";
$message. = "The referring page was: $HTTP _referer";

# Send the mail message. This assumes mail () would 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 users browser
Print_details ();

# See whether or not we should send a 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

?>


http://www.bkjia.com/PHPjc/532620.html www.bkjia.com true http://www.bkjia.com/PHPjc/532620.html techarticle # 404.php, 8/10/2000. # Traps 404 errors and mails a notice to the webmaster. # Requires PHP 3.0 or newer, and mail Capability on your system. # # Copyright shaun@shat.net u ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.