1. The main document, accessed by the page, sets the return status header (' http/1.1 '. $code. ') of this file according to the return result of the "Validate page". '. $_status[$code])
Copy Code code as follows:
<?php
Ini_set (' Max_execution_time ', 120);
Include ("checkconfig.php");
function Send_http_status ($code) {
Static $_status = Array (
Informational 1xx
=> ' Continue ',
=> ' Switching protocols ',
Success 2xx
=> ' OK ',
=> ' Created ',
=> ' accepted ',
=> ' non-authoritative information ',
=> ' No Content ',
=> ' Reset Content ',
=> ' Partial Content ',
Redirection 3xx
=> ' Multiple choices ',
=> ' Moved Permanently ',
=> ' moved temporarily ',//1.1
=> ' to other ',
=> ' Not Modified ',
=> ' Use Proxy ',
306 is deprecated but reserved
=> ' Temporary Redirect ',
Client Error 4xx
=> ' Bad Request ',
=> ' Unauthorized ',
=> ' Payment Required ',
=> ' Forbidden ',
=> ' Not Found ',
=> ' method is not allowed ',
=> ' not acceptable ',
=> ' Proxy authentication Required ',
=> ' Request Timeout ',
=> ' Conflict ',
=> ' Gone ',
=> ' Length Required ',
=> ' Precondition Failed ',
=> ' Request Entity Too Large ',
=> ' Request-uri Too Long ',
=> ' Unsupported Media Type ',
=> ' requested Range not satisfiable ',
=> ' expectation Failed ',
Server Error 5xx
=> ' Internal Server Error ',
=> ' not implemented ',
=> ' Bad Gateway ',
=> ' Service unavailable ',
=> ' Gateway Timeout ',
=> ' HTTP Version not supported ',
=> ' Bandwidth Limit exceeded '
);
if (Array_key_exists ($code, $_status)) {
Header (' http/1.1 '. $code. ' '. $_status[$code]);
}
}
function Getstatuscode ($url)
{
$curl = Curl_init ();
curl_setopt ($curl, Curlopt_url, $url);//Set URL
curl_setopt ($curl, Curlopt_header, 1); Get header
curl_setopt ($curl, curlopt_nobody,true);//body don't. We just need head
curl_setopt ($curl, Curlopt_returntransfer, 1); Save the data to a string, don't give me a direct output to the screen
$data = curl_exec ($curl);//Start execution ~
$HttpCode =curl_getinfo ($curl, Curlinfo_http_code); I know httpstat code. Oh ~
curl_close ($curl);////And turn him off
return $HttpCode;
}
function Reseturl ($url)
{
if (Strpos ($url, "?") >0)
$url. = "&rnd";
Else
$url. = "Rnd";
$url. =rand ();
return $url;
}
function Showstateinfo ($URLARR, $MailPara)
{
$count =count ($URLARR);
if (Isset ($_request["Start"))
{
$start =$_request["Start"]*1;
}
Else
{
$start = 1;
}
if (Isset ($_request["End"))
{
$end =$_request["End"]*1;
}
Else
{
$end = $start;
}
$start = $start-1;
$end = $end-1;
if ($start <0)
{
$start = 0;
}
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 "Start time". $sTime. " <br/> ";
echo "Test results <br/>";
for ($i = $start; $i <= $end; $i + +)
{
$url =reseturl ($URLARR [$i]);
$state =getstatuscode ($url);
echo "". $state. "=> <a href= ' http://". $url. "' target= ' _blank ' > '. $url." <a> ";
if ($state!= "200")
{
echo "<span style= ' color:red;font-weight:bold ' > This article access Error!" </span><br/> ";
Send_http_status ($state);
//Outgoing mail
require ("mail.php");
$MailPara ["Subject"]= "website monitoring results";
$MailPara ["Body]=" error message: status-><span style= ' Color:red;font-weight:bold ' > ". $state." </span><br/> address: ". $url;
Sendresultmail ($MailPara);
Break
}
echo "<br/>";
}
$eTime =date ("y/m/d h:m:s");
echo "End Time". $eTime. " <br/> ";
}
}
Showstateinfo ($URLARR, $MailPara);
?>
2. Mail
Copy Code code as follows:
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 message failed to send. <p> ";
echo "Error Reason:". $mail->errorinfo. " <br/> ";
Exit
}
echo "Mail sent successfully <br/>";
}
3. Configuration file
Copy Code code as follows:
<?php
$URLARR =array (
"Localhost/test/281892.shtml",
"Localhost/test/all-229-1-221.shtml",
"Localhost/testclass/all-254-1-1.shtml",
"Localhost/test/cheng/bd/1988478.html",
"Localhost/test/asd/2066495.html"
);
Mailbox Send related information
$MailPara =array (
"CharSet" => "GB2312",
"Host" => "smtp.exmail.qq.com",//Mailbox service address
"Port" =>25,
"Frommail" => "fdsafdsafd@fdasfds.com",//Sender's email address
"Frommailpassword" => "*********",//sender's mailbox password
"Frommailname" => "detection",//Name of sender
"To" =>array (
Array
"Tomail" => "defdafdsafdsafdf@qq.com",//Recipient email Address
"Tomailname" => "BQQ",//Recipient Salutation
),
Array
"Tomail" => "abfdsafdsafdsafc@gmail.com",//Recipient email Address
"Tomailname" => "Agmail",//Recipient Salutation
)
),
"Subject" => "",//Mail header
"Body" => "",//mail content
"Altbody" => "Additional Information"//additional information that can be omitted
);
?>
The main use of the message is "Phpmailer",
Click to download