Home >Backend Development >PHP Tutorial >404 error php 404 error page implementation code

404 error php 404 error page implementation code

WBOY
WBOYOriginal
2016-07-29 08:40:081012browse

Copy the code The code is as follows:


# Set $domain as your domain name (note there is no www)
$domain = "jb51.net";
# Set the URL, note there is no trailing slash Line/
$docroot = "http://jb51.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 is white
$bgcolor = "#ffffff";
# Set the text color, the default is black
$textcolor = "#000000";
# Use the $reportlevel variable to control whether to send the message to Network administrator
# 0 = No need to send a message at all, hey, how could we go wrong in NB?
# 1 = Only send a message when the page contains your DOMAIN NAME
# 2 = Send even if the connection to me is disconnected Letter, it may be a friendly site
$reportlevel = 2; //This is the safest method
$emailaddress = "webmaster@jb51.net"; //Set the email address 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 "< head>404 Page not found";
echo "";
echo "404 Sorry, I did not find the page you requested";
echo "

echo "oncoding coding camp reminds you that the page you requested, $docroot$REQUEST_URI, doesn't exist";
echo " on this server.

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

";
echo "The error message has been sent to the oncoding coding 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;
# Customized sending
$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 message
return;
}
# The following are based on the setting of the variable $reportlevel to send or not the message.
print_details();
# See whether or not we should 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 introduces the 404 error php 404 error page implementation code, including the content of 404 error. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn