PHP 404 error page implementation code _php instance

Source: Internet
Author: User
Copy Code code as follows:

<?php
# set $domain for your domain (note no www)
$domain = "Jb51.net";
# set URL, note no underline/
$docroot = "Http://jb51.net";
# Set the font for error messages
$fontface = "Verdana";
# Set the font size of 404 pages
$fontsize = "2";
# Set the background color of the 404 page, the default is white
$bgcolor = "#ffffff";
# set text color, default is black
$textcolor = "#000000";
# Use $reportlevel variables to control whether a letter is sent to the network administrator
# 0 = no letters at all, hey, NB. How could we have gone wrong?
# 1 = Send a letter only if the page contains your domain name
# 2 = Even if it is connected with my connection, also send a letter, there may be a friendship site
$reportlevel = 2; This is the safest.
$emailaddress = "Webmaster@jb51.net"; Set up mailboxes 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 "echo "<body bgcolor=" $bgcolor "text=" $textcolor ">";
echo "<b>echo "<p><font face=" $fontface "size=" $fontsize ">";
echo "oncoding Code Battalion reminds you that the page you requested $docroot $request_uri, doesn ' t exist";
echo "on this server.</font></p>";
if ($reportlevel!= 0)
{
echo "<p><font face=" $fontface "size=" $fontsize ">";
echo "error message has been sent to the Oncoding Code battalion Administrator 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", $message, "from: $emailaddress"); Send a message
Return
}
# Here are the letters or not based on the settings of the variable $reportlevel.
Print_details ();
# Whether or not we should send an email. 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.