复制代码代码如下:
#设置$domain为你的域名(注意没有www)
$domain="jb51.net";
#设置URL,注意没有后划线/
$docroot="http://jb51.net";
#设置错误信息的字体
$fontface="Verdana";
#设置404页面的字体大小
$fontsize="2";
#设置404页面的背景颜色,缺省是白色
$bgcolor="#ffffff";
#设置文字颜色,缺省是黑色
$textcolor="#000000";
#使用$reportlevel变量来控制是否发信给网管
#0=根本不用发信,嘿,NB的我们怎么会出错呢
#1=只有在页面含有你的DOMAINNAME时才发信
#2=即使是与我连接出现的断连也发信,有可能是友情站点
$reportlevel=2;//这种最保险了
$emailaddress="webmaster@jb51.net";//设置收错误信息的邮箱
functionprint_details()
{
#Requestaccesstotheglobalvariablesweneed
global$fontface,$fontsize,$docroot,$REQUEST_URI,$reportlevel;
global$bgcolor,$textcolor;
#Printthe404errorinwebformat
echo"
404没有找到页面";echo"";
echo"
404对不起,我没有找到您要求的页面
";echo"
";
echo"oncoding编码营提醒您,您要求的页面$docroot$REQUEST_URI,doesn'texist";
echo"onthisserver.
";if($reportlevel!=0)
{
echo"
";
echo"错误信息已经发送到oncoding编码营管理员信箱.";
}
return;
}
#EMAIL处理函数
functionsend_email()
{
#Requestaccesstotheglobalvariablesweneed
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/$yearat$hours:$minutes";
#Createthebodyoftheemailmessage
$message.="404ErrorReportnnA404errorwasencounteredby$REMOTE_ADDR";
$message.="on$errortime.nn";
$message.="TheURIwhichgeneratedtheerroris:n$docroot$REQUEST_URInn";
$message.="Thereferringpagewas:n$HTTP_REFERERnn";
#Sendthemailmessage.Thisassumesmail()willworkonyoursystem!
mail("$emailaddress","404ErrorReport",$message,"From:$emailaddress");//发送信息
return;
}
#下面这些是根据变量$reportlevel的设置来发信与否。
print_details();
#Seewhetherornotweshouldsendanemailreport.Ifso,doit.
if($reportlevel!=0)
if($reportlevel==1){
if(eregi($domain,$HTTP_REFERER))
send_email();}
else
send_email();
#Alldone!
exit;
?>
您可能感兴趣的文章:php定义404页面的实现代码ThinkPHP3.2.3框架实现的空模块、空控制器、空操作,跳转到错误404页面图文详解thinkphp框架下404页面设置仅三步ThinkPHP404页面的设置方法ThinkPHP访问不存在的模块跳转到404页面的方法php使用curl判断网页404(不存在)的方法PHPheader()函数使用详细(301、404等错误设置)用php来改写404错误页让你的页面更友好php智能404跳转代码,适合换域名没改变目录的网站thinkPHP5框架设置404、403等http状态页面的方法PHP统计nginx访问日志中的搜索引擎抓取404链接页面路径php简单检测404页面的方法示例