php 404错误页面实现代码


Posted in PHP onJune 22, 2009
<?php 
# 设置 $domain 为你的域名 (注意没有www) 
$domain = "3water.com"; 
# 设置URL,注意没有后划线 / 
$docroot = "http://3water.com"; 
# 设置错误信息的字体 
$fontface = "Verdana"; 
# 设置404页面的字体大小 
$fontsize = "2"; 
# 设置404页面的背景颜色,缺省是白色 
$bgcolor = "#ffffff"; 
# 设置文字颜色,缺省是黑色 
$textcolor = "#000000"; 
# 使用 $reportlevel 变量来控制是否发信给网管 
# 0 = 根本不用发信,嘿,NB的我们怎么会出错呢 
# 1 = 只有在页面含有你的DOMAIN NAME时才发信 
# 2 = 即使是与我连接出现的断连也发信,有可能是友情站点 
$reportlevel = 2; //这种最保险了 
$emailaddress = "webmaster@3water.com"; //设置收错误信息的邮箱 
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; 
?>
PHP 相关文章推荐
php实现建立多层级目录的方法
Jul 19 PHP
PHP的pcntl多进程用法实例
Mar 19 PHP
PHP脚本监控Nginx 502错误并自动重启php-fpm
May 13 PHP
PHP微信刮刮卡 附微信接口
Jul 22 PHP
PHP用户验证和标签推荐的简单使用
Oct 31 PHP
PHP页面跳转实现延时跳转的方法
Dec 10 PHP
PHP异常处理定义与使用方法分析
Jul 25 PHP
PHP实现的简单在线计算器功能示例
Aug 02 PHP
Laravel中七个非常有用但很少人知道的Carbon方法
Sep 21 PHP
PHP中上传文件打印错误错误类型分析
Apr 14 PHP
php面向对象重点知识分享
Sep 27 PHP
php实现自动生成验证码的实例讲解
Nov 17 PHP
PHP 多进程 解决难题
Jun 22 #PHP
PHP 高级课程笔记 面向对象
Jun 21 #PHP
mysql 性能的检查和优化方法
Jun 21 #PHP
php fckeditor 调用的函数
Jun 21 #PHP
学习discuz php 引入文件的方法DISCUZ_ROOT
Jun 21 #PHP
php 分页函数multi() discuz
Jun 21 #PHP
一个php Mysql类 可以参考学习熟悉下
Jun 21 #PHP
You might like
php获取qq用户昵称和在线状态(实例分析)
2013/10/27 PHP
php文件压缩之PHPZip类用法实例
2015/06/18 PHP
smarty高级特性之过滤器的使用方法
2015/12/25 PHP
详解PHP的Yii框架中自带的前端资源包的使用
2016/03/31 PHP
PHP简单预防sql注入的方法
2016/09/27 PHP
PHP折半(二分)查找算法实例分析
2018/05/12 PHP
PHP开启目录引索+fancyindex漂亮目录浏览带搜索功能
2019/09/23 PHP
javascript showModalDialog,open取得父窗口的方法
2010/03/10 Javascript
jquery控制listbox中项的移动并排序的实现代码
2010/09/28 Javascript
jQuery技巧总结
2011/01/01 Javascript
jquery的ajax()函数传值中文乱码解决方法介绍
2012/11/08 Javascript
利用jQuery实现打字机字幕效果实例代码
2016/09/02 Javascript
深入浅出es6模板字符串
2017/08/26 Javascript
js的新生代垃圾回收知识点总结
2019/08/22 Javascript
vue-router结合vuex实现用户权限控制功能
2019/11/14 Javascript
js生成1到100的随机数最简单的实现方法
2020/02/07 Javascript
详解python单例模式与metaclass
2016/01/15 Python
Python中shape计算矩阵的方法示例
2017/04/21 Python
Python模拟三级菜单效果
2017/09/11 Python
Python实现Pig Latin小游戏实例代码
2018/02/02 Python
python 列表删除所有指定元素的方法
2018/04/19 Python
Python实现按中文排序的方法示例
2018/04/25 Python
tensorflow 输出权重到csv或txt的实例
2018/06/14 Python
python中Django文件上传方法详解
2020/08/05 Python
pytorch 中forward 的用法与解释说明
2021/02/26 Python
css3 border旋转时的动画应用
2016/01/22 HTML / CSS
6号汽车旅馆预订:Motel 6
2018/02/11 全球购物
成品仓管员工作职责
2013/12/29 职场文书
运动会表扬稿大全
2014/01/16 职场文书
科学发展观标语
2014/10/08 职场文书
2014年扫黄打非工作总结
2014/12/03 职场文书
2016个人先进事迹材料范文
2016/03/01 职场文书
《追风筝的人》:人心中的成见是座大山,但请不忘初心
2019/11/15 职场文书
python基础之匿名函数详解
2021/04/21 Python
python 远程执行命令的详细代码
2022/02/15 Python
十大最强格斗系宝可梦,超梦X仅排第十,第二最重格斗礼仪
2022/03/18 日漫