定制404錯(cuò)誤頁(yè)面,并發(fā)信給管理員的程序
更新時(shí)間:2006年10月09日 00:00:00 作者:
如果您的用戶(hù)找不到他要的頁(yè)面,如何給他一個(gè)友好的答復(fù),并且你也知道發(fā)生了這個(gè)錯(cuò)誤呢,看看下面這段程序,是用來(lái)定制404錯(cuò)誤頁(yè)面和發(fā)通知給網(wǎng)管的好東西。---teaman翻譯整理
<?php
# 設(shè)置 $domain 為你的域名 (注意沒(méi)有www)
$domain = "oso.com.cn";
# 設(shè)置URL,注意沒(méi)有后劃線(xiàn) /
$docroot = "http://www.oso.com.cn";
# 設(shè)置錯(cuò)誤信息的字體
$fontface = "Verdana";
# 設(shè)置404頁(yè)面的字體大小
$fontsize = "2";
# 設(shè)置404頁(yè)面的背景顏色,缺省是白色
$bgcolor = "#ffffff";
# 設(shè)置文字顏色,缺省是黑色
$textcolor = "#000000";
# 使用 $reportlevel 變量來(lái)控制是否發(fā)信給網(wǎng)管
# 0 = 根本不用發(fā)信,嘿,teaman怎么會(huì)出錯(cuò)呢
# 1 = 只有在頁(yè)面含有你的DOMAIN NAME時(shí)才發(fā)信
# 2 = 即使是與我連接出現(xiàn)的斷連也發(fā)信,有可能是友情站點(diǎn)
$reportlevel = 2; //這種最保險(xiǎn)了
$emailaddress = "webmaster@oso.com.cn"; //設(shè)置收錯(cuò)誤信息的郵箱
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 沒(méi)有找到頁(yè)面</title></head>";
echo "<body bgcolor="$bgcolor" text="$textcolor">";
echo "<b><h1>404 對(duì)不起,我沒(méi)有找到您要求的頁(yè)面</h1></b>";
echo "<p><font face="$fontface" size="$fontsize">";
echo "奧索網(wǎng)管提醒您,您要求的頁(yè)面 $docroot$REQUEST_URI, doesn't exist";
echo " on this server.</font></p>";
if ($reportlevel != 0)
{
echo "<p><font face="$fontface" size="$fontsize">";
echo "錯(cuò)誤信息已經(jīng)發(fā)送到奧索網(wǎng)管手中.";
}
return;
}
# EMAIL處理函數(shù)
function send_email()
{
# Request access to the global variables we need
global $REQUEST_URI, $HTTP_REFERER, $emailaddress, $REMOTE_ADDR, $docroot;
# 定制發(fā)送的消息,如時(shí)間地點(diǎn)等.
$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"); //好,把信發(fā)出去
return;
}
# 下面這些是根據(jù)變量$reportlevel的設(shè)置來(lái)發(fā)信與否。
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
# 設(shè)置 $domain 為你的域名 (注意沒(méi)有www)
$domain = "oso.com.cn";
# 設(shè)置URL,注意沒(méi)有后劃線(xiàn) /
$docroot = "http://www.oso.com.cn";
# 設(shè)置錯(cuò)誤信息的字體
$fontface = "Verdana";
# 設(shè)置404頁(yè)面的字體大小
$fontsize = "2";
# 設(shè)置404頁(yè)面的背景顏色,缺省是白色
$bgcolor = "#ffffff";
# 設(shè)置文字顏色,缺省是黑色
$textcolor = "#000000";
# 使用 $reportlevel 變量來(lái)控制是否發(fā)信給網(wǎng)管
# 0 = 根本不用發(fā)信,嘿,teaman怎么會(huì)出錯(cuò)呢
# 1 = 只有在頁(yè)面含有你的DOMAIN NAME時(shí)才發(fā)信
# 2 = 即使是與我連接出現(xiàn)的斷連也發(fā)信,有可能是友情站點(diǎn)
$reportlevel = 2; //這種最保險(xiǎn)了
$emailaddress = "webmaster@oso.com.cn"; //設(shè)置收錯(cuò)誤信息的郵箱
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 沒(méi)有找到頁(yè)面</title></head>";
echo "<body bgcolor="$bgcolor" text="$textcolor">";
echo "<b><h1>404 對(duì)不起,我沒(méi)有找到您要求的頁(yè)面</h1></b>";
echo "<p><font face="$fontface" size="$fontsize">";
echo "奧索網(wǎng)管提醒您,您要求的頁(yè)面 $docroot$REQUEST_URI, doesn't exist";
echo " on this server.</font></p>";
if ($reportlevel != 0)
{
echo "<p><font face="$fontface" size="$fontsize">";
echo "錯(cuò)誤信息已經(jīng)發(fā)送到奧索網(wǎng)管手中.";
}
return;
}
# EMAIL處理函數(shù)
function send_email()
{
# Request access to the global variables we need
global $REQUEST_URI, $HTTP_REFERER, $emailaddress, $REMOTE_ADDR, $docroot;
# 定制發(fā)送的消息,如時(shí)間地點(diǎn)等.
$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"); //好,把信發(fā)出去
return;
}
# 下面這些是根據(jù)變量$reportlevel的設(shè)置來(lái)發(fā)信與否。
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來(lái)改寫(xiě)404錯(cuò)誤頁(yè)讓你的頁(yè)面更友好
- php 定義404頁(yè)面的實(shí)現(xiàn)代碼
- IIS設(shè)置404頁(yè)面圖文教程(選擇URL還是文件 )
- asp.net網(wǎng)站的404錯(cuò)誤頁(yè)面的正確設(shè)置方法
- asp.net 在global中攔截404錯(cuò)誤的實(shí)現(xiàn)方法
- php 404錯(cuò)誤頁(yè)面實(shí)現(xiàn)代碼
- 運(yùn)行asp.net時(shí)出現(xiàn) http錯(cuò)誤404-文件或目錄未找到
- 定制 404 頁(yè)面的一些心得
- flex 開(kāi)發(fā)項(xiàng)目報(bào)錯(cuò)之404錯(cuò)誤解決方案
相關(guān)文章
PHP中基于ts與nts版本- vc6和vc9編譯版本的區(qū)別詳解
本篇文章介紹了,PHP中基于ts與nts版本- vc6和vc9編譯版本的區(qū)別詳解。需要的朋友參考下2013-04-04vBulletin Forum 2.3.xx SQL Injection
vBulletin Forum 2.3.xx SQL Injection...2006-10-10用定制的PHP應(yīng)用程序來(lái)獲取Web服務(wù)器的狀態(tài)信息
用定制的PHP應(yīng)用程序來(lái)獲取Web服務(wù)器的狀態(tài)信息...2006-10-10不用GD庫(kù)生成當(dāng)前時(shí)間的PNG格式圖象的程序
不用GD庫(kù)生成當(dāng)前時(shí)間的PNG格式圖象的程序...2006-10-10