当前位置: 移动技术网 > IT编程>开发语言>PHP > php 404错误页面实现代码

php 404错误页面实现代码

2019年05月04日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

<?php
# 设置 $domain 为你的域名 (注意没有www)
$domain = "jb51.net";
# 设置url,注意没有后划线 /
$docroot = "http://jb51.net";
# 设置错误信息的字体
$fontface = "verdana";
# 设置404页面的字体大小
$fontsize = "2";
# 设置404页面的背景颜色,缺省是白色
$bgcolor = "#ffffff";
# 设置文字颜色,缺省是黑色
$textcolor = "#000000";
# 使用 $reportlevel 变量来控制是否发信给网管
# 0 = 根本不用发信,嘿,nb的我们怎么会出错呢
# 1 = 只有在页面含有你的domain name时才发信
# 2 = 即使是与我连接出现的断连也发信,有可能是友情站点
$reportlevel = 2; //这种最保险了
$emailaddress = "webmaster@jb51.net"; //设置收错误信息的邮箱
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 没有找到页面</title></head>";
echo "<body bgcolor="$bgcolor" text="$textcolor">";
echo "<b><h1>404 对不起,我没有找到您要求的页面</h1></b>";
echo "<p><font face="$fontface" size="$fontsize">";
echo "oncoding编码营提醒您,您要求的页面 $docroot$request_uri, doesn't exist";
echo " on this server.</font></p>";
if ($reportlevel != 0)
{
echo "<p><font face="$fontface" size="$fontsize">";
echo "错误信息已经发送到oncoding编码营管理员信箱.";
}
return;
}
# email处理函数
function send_email()
{
# request access to the global variables we need
global $request_uri, $http_referer, $emailaddress, $remote_addr, $docroot;
# 定制发送的消息,如时间地点等.
$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"); //发送信息
return;
}
# 下面这些是根据变量$reportlevel的设置来发信与否。
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;
?>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网