PHP Analog post_ Validation page return status (instance explanation) _php instance

Source: Internet
Author: User
Tags curl echo message

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 &lt; $start)


{


$end = $start;


}


$sTime =date ("y/m/d h:m:s");


echo "Start time". $sTime. " &lt;br/&gt; ";


echo "Test results &lt;br/&gt;";


for ($i = $start; $i &lt;= $end; $i + +)


{


$url =reseturl ($URLARR [$i]);


$state =getstatuscode ($url);


echo "". $state. "=&gt; &lt;a href= ' http://". $url. "' target= ' _blank ' &gt; '. $url." &lt;a&gt; ";


if ($state!= "200")


{


echo "&lt;span style= ' color:red;font-weight:bold ' &gt; This article access Error!" &lt;/span&gt;&lt;br/&gt; ";


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:



&lt;?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" =&gt; "fdsafdsafd@fdasfds.com",//Sender's email address


"Frommailpassword" =&gt; "*********",//sender's mailbox password


"Frommailname" =&gt; "detection",//Name of sender





"To" =&gt;array (


Array


"Tomail" =&gt; "defdafdsafdsafdf@qq.com",//Recipient email Address


"Tomailname" =&gt; "BQQ",//Recipient Salutation


),


Array


"Tomail" =&gt; "abfdsafdsafdsafc@gmail.com",//Recipient email Address


"Tomailname" =&gt; "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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.