Custom 404 error page, concurrent letter to Administrator program

Source: Internet
Author: User
If your users can not find the page he wants, how to give him a friendly reply, and you know that this error has occurred, look at the following program, is used to customize the 404 error page and send notifications to the network management of good things. ---teaman translation and Finishing
# set $domain for your domain (note no www)
$domain = "oso.com.cn";
# set URL, note no post-dash/
$docroot = "http://www.oso.com.cn";
# Set font for error messages
$fontface = "Verdana";
# Set the font size for 404 pages
$fontsize = "2";
# set 404 page background color, default is white
$bgcolor = "#ffffff";
# set text color, default is black
$textcolor = "#000000";
# Use $reportlevel variables to control whether or not to send to the network
# 0 = no letters at all, hey, how could teaman go wrong?
# 1 = Send a letter only if the page contains your domain name
# 2 = Even if it is connected with my connection also sent a letter, it may be a friendship site
$reportlevel = 2; This is the most insured.
$emailaddress = "webmaster@oso.com.cn"; Set up a mailbox to receive error messages
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 " <title>404 Page Not Found</title>";
echo "";
echo "

404 Sorry, I did not find the page you requested

";
echo "

";
echo "The Web management reminds you that the page you requested $docroot $request_uri, doesn ' t exist";
echo "on the This server.

";
if ($reportlevel! = 0)
{
echo "

";
echo "error message has been sent to the House Orso near network management hands.";
}
Return
}
# Email processing function
function Send_email ()
{
# Request access to the global variables we need
Global $REQUEST _uri, $HTTP _referer, $emailaddress, $REMOTE _addr, $docroot;
# Custom sent messages, such as time and place.
$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 Reportnna 404 error is encountered by $REMOTE _addr";
$message. = "on $errortime. nn";
$message. = "The URI which generated the error Is:n$docroot$request_urinn";
$message. = "The referring page was:n$http_referernn";
# Send the mail message. This assumes mail () would work on your system!
Mail ("$emailaddress", "404 Error Report", $message, "from: $emailaddress"); All right, send out the letter.
Return
}
# Here are the letters or not based on the settings of the variable $reportlevel.
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
?>

The above describes the custom 404 error page, concurrent letter to the administrator of the program, including the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.