欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【PHP:404错误陷阱并email给管理员的程序】,下面是详细的分享!
PHP:404错误陷阱并email给管理员的程序
<?
#404.php,8/10/2000.
#Traps404errorsandmailsanoticetothewebmaster.
#RequiresPHP3.0ornewer,andmailcapabilityonyoursystem.
#
#Copyright2000shaun@shat.netundertheGNUPublicLicense.
#Disclaimer:Iwrotethisscriptforme,anditworksforme.
#Ifitdoesn'tworkforyou,ormakesyourserverexplode,
#that'slife.Pleaseemailwithquestionsorbugreports.
#Setthesevariablestoconfigurethescript:
#Set$domaintoyourdomainname(nowww)
$domain="your.domain.com";
#Set$docroottotheURLofthedirectorywhichcontainsyour
#.htaccessfile.Don'tincludetrailingslash.
$docroot="http://your.domain.com";
#Fontfaceyou'dliketouseonthe404page
$fontface="Verdana";
#Fontsizeyou'dliketouseonthe404page
$fontsize="2";
#Backgroundcolorofthe404page(defaultiswhite)
$bgcolor="#ffffff";
#Textcoloryou'dliketouseonthe404page(defaultisblack)
$textcolor="#000000";
#Thisscriptiscapableofmailingthedetailsofeach404error
#tothewebmaster.Usethe$reportlevelvariabletocontrolwhen
#youreceivethesereports.
#
#0=don'tusetheemailcapabilitiesatall
#1=sendemailonlyiftheerror'sreferercontainsyourdomainname
#(i.e.the404wasgeneratedbyabrokenlinkonyoursite)
#2=sendemailanytimea404errorisgenerated(usefulfortracking
#brokenlinksatothersiteswhichlinktoyou)
$reportlevel=2;
#Set$emailaddresstotheemailaddressofwhoevershouldbe
#notifiedof404errors.Don'tescapethe@symbol.Thiswillalso
#beusedasthe"from"addressonanyemailsthescriptgenerates.
#Youcanleavethisunassignedifyou'renotusingemailfeatures.
$emailaddress="you@your.domain.com";
################################################################
#DON'TEDITBELOWTHISLINEUNLESSYOUKNOWWHATYOU'REDOING#
################################################################
#Ifyouwanttoeditthescript,I'vecommentedprofusely:)#
################################################################
#Theprint_detailsfunctioniswhatprintsthe404errorto
#thevisitor.AsfarasIknow,PHP3doesn'tincorporatePerl's
#print<<"EOT"ability.PHP4doesallowthiscapability
#butthescriptwaswrittenforPHP3.So,youhavetouse
#alotofechostatementsifyouwanttoretainPHP3compat.
functionprint_details()
{
#Requestaccesstotheglobalvariablesweneed
global$fontface,$fontsize,$docroot,$REQUEST_URI,$reportlevel;
global$bgcolor,$textcolor
#Printthe404errorinwebformat
echo"<html><head><title>404NotFound</title></head>";
echo"<bodybgcolor=\"$bgcolor\"text=\"$textcolor\">";
echo"<b><h1>404NotFound</h1></b>";
echo"<p><fontface=\"$fontface\"size=\"$fontsize\">";
echo"We'resorry.Thepageyourequested,$docroot$REQUEST_URI,doesn'texist";
echo"onthisserver.</font></p>";
#Ifanemailreportisbeinggenerated,letthevisitorknow:
if($reportlevel!=0)
{
echo"<p><fontface=\"$fontface\"size=\"$fontsize\">";
echo"Thedetailsofthiserrorhaveautomaticallybeenmailedtothewebmaster.";
}
#CloseuptheHTMLtags
#echo"</body></html>";
return;
}
#Thesend_emailfunctionsendsthedetailsofthe404errortothe
#webmaster.
functionsend_email()
{
#Requestaccesstotheglobalvariablesweneed
global$REQUEST_URI,$HTTP_REFERER,$emailaddress,$REMOTE_ADDR,$docroot;
#Buildthe$errortimevariabletocontainthedate/timeoftheerror.
#Usingdate()likelywouldhavebeenbetter,butIalreadyhadthiscode
#elsewhere,andI'mlazy.
$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.="404ErrorReport\n\nA404errorwasencounteredby$REMOTE_ADDR";
$message.="on$errortime.\n\n";
$message.="TheURIwhichgeneratedtheerroris:\n$docroot$REQUEST_URI\n\n";
$message.="Thereferringpagewas:\n$HTTP_REFERER\n\n";
#Sendthemailmessage.Thisassumesmail()willworkonyoursystem!
mail("$emailaddress","404ErrorReport",$message,"From:$emailaddress");
return;
}
#Donewithfunctiondeclarations.Mainfunctionbeginshere.
#Senda404errortotheuser'sbrowser
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错误陷阱并email给管理员的程序,下面是编辑为你推荐的有价值的用户互动:
相关问题:THHT 404 错误了怎么办阿,。,,
答:404页面就是当用户输入了错误的链接时,返回的页面。 404页面的目的是:告诉浏览者其所请求的页面不存在或链接错误,同时引导用户使用网站其他页面而不是关闭窗口离开。 404对seo的影响 自定义404错误页面是增强用户体验的很好的做法,但在应用... >>详细
相关问题:PHP的程序,打开网站偶尔会出现404错误的提示,是...
答:从页面来看,只有一个地方出现,可能的情况是,页面中包含了 framset之类的引用,但是该也没找到,但是其他framset的页面找到了 >>详细
相关问题:我的 IIS 提示 HTTP 错误 404 - 文件或目录未找到。
答:解决方法就是把WEB服务扩展中的active servers pages 给允许起来。。有时开启了.net功能是不用开的。但如是不行的话还是要开的。。 默认任何版本的 Windows Server 2003 家族, 上安装 IIS 时 IIS 只支持静态内容 (HTML)。 解决方法 当确实要使用... >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
