Home Backend Development PHP Tutorial Program to customize the 404 error page and send a letter to the administrator_PHP tutorial

Program to customize the 404 error page and send a letter to the administrator_PHP tutorial

Jul 21, 2016 pm 04:03 PM
404 how custom made try to find user of program administrator mistake page

If your user cannot find the page he is looking for, how to give him a friendly reply, and you also know that this error has occurred? Take a look at the following program, which is used to customize the 404 error page and send a notification to the network administrator. nice one. ---teaman translation

<?php
# Set $domain as your domain name (note there is no www)
$domain = "oso.com.cn";
# Set the URL, note there is no trailing underscore/
$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 is white
$bgcolor = "#ffffff";
# Set the text Color, the default is black
$textcolor = "#000000";

# Use the $reportlevel variable to control whether to send a letter to the network administrator
# 0 = No need to send a letter at all, hey, how about teaman What will go wrong
# 1 = Only send emails when the page contains your DOMAIN NAME
# 2 = Send emails even if the connection to me is disconnected, it may be a friendly site
$reportlevel = 2; //This is the safest method

$emailaddress = "webmaster@oso.com.cn"; //Set the email address 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 "<html><head><title>404 Page not found</title></head>";
echo "<body bgcolor="$bgcolor" text="$textcolor">";
echo "<b><h1>404 Sorry, I did not find the page you requested</h1></b>" ;
echo "<p><font face="$fontface" size="$fontsize">";
echo "Oso Network Administrator reminds you that the page you requested, $docroot$REQUEST_URI, doesn't 't exist";
echo " on this server.</font></p>";

if ($reportlevel != 0)
echo "&lt ;p><font face="$fontface" size="$fontsize">";
echo "The error message has been sent to the Oso network administrator.";
}

return ;
}


# EMAIL processing function

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

# Customize the message sent, such as 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"); //Okay, send the message

return;
}


# The following are based on the variable $reportlevel settings to send messages or not.
print_details();

# See whether or not we should send an email report. If so, do it.
if ($reportlevel != 0) 
if ($reportlevel = = 1) {                                                                                                                             exit;

?>




http://www.bkjia.com/PHPjc/316295.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/316295.htmlTechArticleIf your user cannot find the page he is looking for, how to give him a friendly reply, and you know This error occurred. Take a look at the following program, which is used to customize the 404 error page and...
Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Xiaohongshu account to find users? Can I find my mobile phone number? How to use Xiaohongshu account to find users? Can I find my mobile phone number? Mar 22, 2024 am 08:40 AM

How to use Xiaohongshu account to find users? Can I find my mobile phone number?

How to make Google Maps the default map in iPhone How to make Google Maps the default map in iPhone Apr 17, 2024 pm 07:34 PM

How to make Google Maps the default map in iPhone

How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? Apr 11, 2024 am 09:10 AM

How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue?

Unable to complete operation (Error 0x0000771) Printer error Unable to complete operation (Error 0x0000771) Printer error Mar 16, 2024 pm 03:50 PM

Unable to complete operation (Error 0x0000771) Printer error

Solution to Windows Update prompt Error 0x8024401c error Solution to Windows Update prompt Error 0x8024401c error Jun 08, 2024 pm 12:18 PM

Solution to Windows Update prompt Error 0x8024401c error

Log in to Ubuntu as superuser Log in to Ubuntu as superuser Mar 20, 2024 am 10:55 AM

Log in to Ubuntu as superuser

Summary of methods to obtain administrator rights in Win11 Summary of methods to obtain administrator rights in Win11 Mar 09, 2024 am 08:45 AM

Summary of methods to obtain administrator rights in Win11

Clock app missing in iPhone: How to fix it Clock app missing in iPhone: How to fix it May 03, 2024 pm 09:19 PM

Clock app missing in iPhone: How to fix it

See all articles