Create a 404 error page and send it to the administrator.

Source: Internet
Author: User
: This article mainly introduces how to create a 404 error page and send it to the Administrator. For more information about PHP tutorials, see. # Set $ domain to your domain name (note that there is no www)
$ Domain = "oso.com.cn ";
# Set the URL. Note that there is no dash/
$ Docroot = "http://www.oso.com.cn ";
# Set the font of the error message
$ Fontface = "Verdana ";
# Set the font size of the 404 page
$ Fontsize = "2 ";
# Set the background color of the 404 page. the default value is white.
$ Bgcolor = "# ffffff ";
# Set the text color. the default value is black.
$ Textcolor = "#000000 ";

# Use the $ reportlevel variable to control whether to send emails to the network administrator.
#0 = do not send emails at all. Hey, how can teaman go wrong?
#1 = send a mail only when the page contains your DOMAIN NAME
#2 = even if a disconnected connection occurs with me, it may be a site of friendship.
$ Reportlevel = 2; // This is the safest

$ Emailaddress = "webmaster@oso.com.cn"; // Set the mailbox for receiving 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 no page found";
Echo"";
Echo" 404 Sorry, I did not find the page you requested";
Echo"

";
Echo "osuo network management reminds you that the requested page $ docroot $ REQUEST_URI, doesn' t exist ";
Echo "on this server.

";

If ($ reportlevel! = 0)
{
Echo"

";
Echo "the error message has been sent to the Osos network administrator .";
}

Return;
}


# EMAIL processing functions

Function send_email ()
{
# Request access to the global variables we need
Global $ REQUEST_URI, $ HTTP_REFERER, $ emailaddress, $ REMOTE_ADDR, $ docroot;

# Customize the sent message, such as the time and location.
$ 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 was 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 () will work on your system!
Mail ("$ emailaddress", "404 Error Report", $ message, "From: $ emailaddress"); // send the email.

Return;
}


# The following describes whether to send emails based on the $ reportlevel variable.
Print_details ();

# See whether or not we shoshould send an 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 how to create a 404 error page and send a mail to the administrator, including some content. I hope my friends who are interested in PHP tutorials will be helpful.

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.