Home Backend Development PHP Tutorial PHP 404 error page implementation code_PHP tutorial

PHP 404 error page implementation code_PHP tutorial

Jul 21, 2016 pm 03:45 PM
404 php for code domain name copy accomplish Notice set up mistake page

Copy the code The code is as follows:

<?php
# Set $domain as your domain name (note there is no www)
$domain = "jb51.net";
# Set the URL, note there is no trailing underscore/
$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 a letter to the network management
# 0 = Basically No need to send a message, hey, how could we go wrong in NB
# 1 = Only send a message when the page contains your DOMAIN NAME
# 2 = Send a message even if the connection to me is disconnected, It may be a friendly site
$reportlevel = 2; //This is the safest option
$emailaddress = "webmaster@jb51.net"; //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 "oncoding coding camp 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 "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;
# Customize the message sent, such as time, place, etc.
$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 whether to send the message or not.
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;
? >

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320358.htmlTechArticleCopy the code as follows: ?php # Set $domain as your domain name (note there is no www) $domain = " jb51.net"; # Set the URL, please note that there is no trailing underscore/ $docroot = "http://jb51.net"; # Wrong setting...
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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles