php 404錯(cuò)誤頁(yè)面實(shí)現(xiàn)代碼
更新時(shí)間:2009年06月22日 00:49:39 作者:
如果訪問(wèn)您站點(diǎn)的用戶由于各種原因暫時(shí)出現(xiàn)無(wú)法訪問(wèn)頁(yè)面的錯(cuò)誤,如何給他一個(gè)友好的答復(fù),并且你也知道發(fā)生了這個(gè)錯(cuò)誤,看看下面這段程序,是用來(lái)定制404錯(cuò)誤頁(yè)面和發(fā)通知給網(wǎng)管。
復(fù)制代碼 代碼如下:
<?php
# 設(shè)置 $domain 為你的域名 (注意沒(méi)有www)
$domain = "jb51.net";
# 設(shè)置URL,注意沒(méi)有后劃線 /
$docroot = "http://jb51.net";
# 設(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ā)信,嘿,NB的我們?cè)趺磿?huì)出錯(cuò)呢
# 1 = 只有在頁(yè)面含有你的DOMAIN NAME時(shí)才發(fā)信
# 2 = 即使是與我連接出現(xiàn)的斷連也發(fā)信,有可能是友情站點(diǎn)
$reportlevel = 2; //這種最保險(xiǎn)了
$emailaddress = "webmaster@jb51.net"; //設(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 "oncoding編碼營(yí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ā)送到oncoding編碼營(yí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簡(jiǎn)單檢測(cè)404頁(yè)面的方法示例
- thinkPHP5框架設(shè)置404、403等http狀態(tài)頁(yè)面的方法
- php使用curl判斷網(wǎng)頁(yè)404(不存在)的方法
- thinkphp框架下404頁(yè)面設(shè)置 僅三步
- ThinkPHP 404頁(yè)面的設(shè)置方法
- ThinkPHP訪問(wèn)不存在的模塊跳轉(zhuǎn)到404頁(yè)面的方法
- 用php來(lái)改寫(xiě)404錯(cuò)誤頁(yè)讓你的頁(yè)面更友好
- php 定義404頁(yè)面的實(shí)現(xiàn)代碼
- PHP使用Apache的偽靜態(tài)功能實(shí)現(xiàn)“網(wǎng)頁(yè)404時(shí)跳轉(zhuǎn)指定頁(yè)面
相關(guān)文章
thinkphp5?操作redis?實(shí)現(xiàn)文章的熱度排行和點(diǎn)贊排行的示例
本文主要介紹了thinkphp5?操作redis?實(shí)現(xiàn)文章的熱度排行和點(diǎn)贊排行的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04TP5(thinkPHP5框架)基于bootstrap實(shí)現(xiàn)的單圖上傳插件用法示例
這篇文章主要介紹了TP5(thinkPHP5框架)基于bootstrap實(shí)現(xiàn)的單圖上傳插件用法,結(jié)合實(shí)例形式分析了thinkPHP5框架結(jié)合bootstrap實(shí)現(xiàn)圖片上傳相關(guān)布局與控制器操作技巧,需要的朋友可以參考下2019-05-05php中計(jì)算程序運(yùn)行時(shí)間的類(lèi)代碼
一個(gè)用來(lái)技術(shù)你程序運(yùn)行時(shí)間的php類(lèi),有需要的朋友可參考一下2012-11-11