404 Error PHP 404 error page implementation code

Source: Internet
Author: User
Copy CodeThe code is as follows:


# set $domain for your domain (note no www)
$domain = "Jb51.net";
# set URL, note no post-dash/
$docroot = "Http://jb51.net";
# 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, NB How could we make a mistake?
# 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@jb51.net"; 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 "404 Page Not Found";
echo "";
echo "

404 Sorry, I did not find the page you requested

";
echo "

";
echo "Oncoding Code Camp 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 Oncoding code Camp Administrator's mailbox.";
}
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"); Send Message
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 404 error PHP 404 error page Implementation code, including the content of 404 errors, I hope to be interested in PHP tutorial friends 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.