Use php to customize the 404 error page and send a message to the administrator.

Source: Internet
Author: User
If the user who visits your site has temporary page access failures due to various reasons, give him a friendly response and you know that this error has occurred. let's look at the following procedure, is used to customize the 404 error page and send notifications to the good east of the network management... page 404

If the user who visits your site has temporary page access failures due to various reasons, give him a friendly response and you know that this error has occurred. let's look at the following procedure, is used to customize the 404 error page and send notifications to the network administrator.

Reference content is as follows:

# Set $ domain to your domain name (note that there is no www)
$ Domain = "oncoding.net ";
# Set the URL. Note that there is no dash/
$ Docroot = "http://oncoding.net ";
# 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 we make an error with NB?
#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@oncoding.net"; // 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 "oncoding Code Camp 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 oncoding camp administrator mailbox .";
}

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 information

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;

?>

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.