您好,欢迎访问一九零五行业门户网

PHP:404错误陷阱并email给管理员的程序_PHP教程

# 404.php, 8/10/2000.
# traps 404 errors and mails a notice to the webmaster.
# requires php 3.0 or newer, and mail capability on your system.
#
# copyright 2000 shaun@shat.net under the gnu public license.
# disclaimer: i wrote this script for me, and it works for me.
# if it doesnt work for you, or makes your server explode,
# thats life. please email with questions or bug reports.
# set these variables to configure the script:
# set $domain to your domain name (no www)
$domain = your.domain.com;
# set $docroot to the url of the directory which contains your
# .htaccess file. dont include trailing slash.
$docroot = http://your.domain.com;
# font face youd like to use on the 404 page
$fontface = verdana;
# font size youd like to use on the 404 page
$fontsize = 2;
# background color of the 404 page (default is white)
$bgcolor = #ffffff;
# text color youd like to use on the 404 page (default is black)
$textcolor = #000000;
# this script is capable of mailing the details of each 404 error
# to the webmaster. use the $reportlevel variable to control when
# you receive these reports.
#
# 0 = dont use the email capabilities at all
# 1 = send email only if the errors referer contains your domain name
# (i.e. the 404 was generated by a broken link on your site)
# 2 = send email any time a 404 error is generated (useful for tracking
# broken links at other sites which link to you)
$reportlevel = 2;
# set $emailaddress to the email address of whoever should be
# notified of 404 errors. dont escape the @ symbol. this will also
# be used as the from address on any emails the script generates.
# you can leave this unassigned if youre not using email features.
$emailaddress = you@your.domain.com;
################################################################
# dont edit below this line unless you know what youre doing #
################################################################
# if you want to edit the script, ive commented profusely :) #
################################################################
# the print_details function is what prints the 404 error to
# the visitor. as far as i know, php3 doesnt incorporate perls
# print # but the script was written for php3. so, you have to use
# a lot of echo statements if you want to retain php3 compat.
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
404 not found;
echo ;
echo 404 not found;
echo ;
echo were sorry. the page you requested, $docroot$request_uri, doesnt exist;
echo on this server.
; # if an email report is being generated, let the visitor know:
if ($reportlevel != 0)
{
echo
;
echo the details of this error have automatically been mailed to the webmaster.;
}
# close up the html tags
# echo ;
return;
}
# the send_email function sends the details of the 404 error to the
# webmaster.
function send_email()
{
# request access to the global variables we need
global $request_uri, $http_referer, $emailaddress, $remote_addr, $docroot;
# build the $errortime variable to contain the date/time of the error.
# using date() likely would have been better, but i already had this code
# elsewhere, and im lazy.
$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 reporta 404 error was encountered by $remote_addr;
$message .= on $errortime.;
$message .= the uri which generated the error is: $docroot$request_uri;
$message .= the referring page was:$http_referer;
# send the mail message. this assumes mail() will work on your system!
mail($emailaddress, 404 error report, $message, from: $emailaddress);
return;
}
# done with function declarations. main function begins here.
# send a 404 error to the users browser
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;
?>
http://www.bkjia.com/phpjc/532620.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/532620.htmltecharticle? # 404.php, 8/10/2000. # traps 404 errors and mails a notice to the webmaster. # requires php 3.0 or newer, and mail capability on your system. # # copyright 2000 shaun@shat.net u...
其它类似信息

推荐信息