1.主要文件,访问该页面,该页面根据“验证页面”的返回结果设置本文件的返回状态 header(‘HTTP/1.1 ‘.$code.’ ‘.$_status[$code])
<?php<BR> ini_set('max_execution_time', 120);</P><P> include("CheckConfig.php");</P><P> function send_http_status($code) {<BR> static $_status = array(<BR> // Informational 1xx<BR>=> 'Continue',<BR>=> 'Switching Protocols',<BR> // Success 2xx<BR>=> 'OK',<BR>=> 'Created',<BR>=> 'Accepted',<BR>=> 'Non-Authoritative Information',<BR>=> 'No Content',<BR>=> 'Reset Content',<BR>=> 'Partial Content',<BR> // Redirection 3xx<BR>=> 'Multiple Choices',<BR>=> 'Moved Permanently',<BR>=> 'Moved Temporarily ', // 1.1<BR>=> 'See Other',<BR>=> 'Not Modified',<BR>=> 'Use Proxy',<BR> // 306 is deprecated but reserved<BR>=> 'Temporary Redirect',<BR> // Client Error 4xx<BR>=> 'Bad Request',<BR>=> 'Unauthorized',<BR>=> 'Payment Required',<BR>=> 'Forbidden',<BR>=> 'Not Found',<BR>=> 'Method Not Allowed',<BR>=> 'Not Acceptable',<BR>=> 'Proxy Authentication Required',<BR>=> 'Request Timeout',<BR>=> 'Conflict',<BR>=> 'Gone',<BR>=> 'Length Required',<BR>=> 'Precondition Failed',<BR>=> 'Request Entity Too Large',<BR>=> 'Request-URI Too Long',<BR>=> 'Unsupported Media Type',<BR>=> 'Requested Range Not Satisfiable',<BR>=> 'Expectation Failed',<BR> // Server Error 5xx<BR>=> 'Internal Server Error',<BR>=> 'Not Implemented',<BR>=> 'Bad Gateway',<BR>=> 'Service Unavailable',<BR>=> 'Gateway Timeout',<BR>=> 'HTTP Version Not Supported',<BR>=> 'Bandwidth Limit Exceeded'<BR> );<BR> if(array_key_exists($code,$_status)) {<BR> header('HTTP/1.1 '.$code.' '.$_status[$code]);<BR> }<BR> }</P><P> function GetStatusCode($url)<BR> {<BR> $curl = curl_init();<BR> curl_setopt($curl, CURLOPT_URL, $url); //设置URL<br><br> curl_setopt($curl, CURLOPT_HEADER, 1); //获取Header<BR> curl_setopt($curl,CURLOPT_NOBODY,true); //Body就不要了吧,我们只是需要Head<BR> curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //数据存到成字符串吧,别给我直接输出到屏幕了<BR> $data = curl_exec($curl); //开始执行啦~<BR> $HttpCode =curl_getinfo($curl,CURLINFO_HTTP_CODE); //我知道HTTPSTAT码哦~<BR> curl_close($curl); //用完记得关掉他<BR> return $HttpCode;<BR> }</P><P> function ResetUrl($url)<BR> {<BR> if(strpos($url,"?")>0)<BR> $url.="&rnd";<BR> else<BR> $url.="?rnd";<BR> $url.=rand();<BR> return $url;<BR> }</P><P> function ShowStateInfo($UrlArr,$MailPara)<BR> {<BR> $count=count($UrlArr);<BR> if(isset($_REQUEST["start"]))<BR> {<BR> $start=$_REQUEST["start"]*1;<BR> }<BR> else<BR> {<BR> $start=1;<BR> }<BR> if(isset($_REQUEST["end"]))<BR> {<BR> $end=$_REQUEST["end"]*1;<BR> }<BR> else<BR> {<BR> $end=$start;<BR> }</P><P> $start=$start-1;<BR> $end=$end-1;</P><P> if($start<0)<BR> {<BR> $start=0;<BR> }</P><P> <div>本文#来源gaodai.ma#com搞##代!^码7网</div><pre>搞代gaodaima码
if($start>=0 && $start<$count)
{
if($end>=$count)
{
$end=$count-1;
}
if($end<$start)
{
$end=$start;
}
$sTime=date(“Y/m/d H:m:s”);
echo “开始时间”.$sTime.”
“;
echo “检测结果
“;
for($i=$start;$i<=$end;$i++)
{
$url=ResetUrl($UrlArr[$i]);
$state=GetStatusCode($url);
echo ” “.$state .” => “.$url.””;
if($state!=”200″)
{
echo ” 本条访问出错!
“;
send_http_status($state);
//发邮件
require(“Mail.php”);
$MailPara[“Subject”]=”网站监控结果”;
$MailPara[“Body”]=”错误信息:状态->“.$state.”
地址:”.$url;
SendResultMail($MailPara);
break;
}
echo “
“;
}
$eTime=date(“Y/m/d H:m:s”);
echo “结束时间”.$eTime.”
“;
}
}
ShowStateInfo($UrlArr,$MailPara);
?>
2.邮件
function SendResultMail($MailPara)
{
require("phpmailer/class.phpmailer.php");$mail = new PHPMailer();
$mail->CharSet = $MailPara["CharSet"];
$mail->IsSMTP();
$mail->Host = $MailPara["Host"];
$mail->Port = $MailPara["Port"];$mail->SMTPAuth = true;
$mail->Username = $MailPara["FromMail"];
$mail->Password = $MailPara["FromMailPassword"];
$mail->From = $MailPara["FromMail"];
$mail->FromName = $MailPara["FromMailName"];foreach($MailPara["To"] as $toMail)
{
$mail->AddAddress($toMail["ToMail"], $toMail["ToMailName"]);
}$mail->Subject = $MailPara["Subject"];
$mail->Body = $MailPara["Body"];
$mail->AltBody = $MailPara["AltBody"];if(!$mail->Send())
{
echo "邮件发送失败.