Php simulated post _ verification page return status (instance description) _ PHP Tutorial

Source: Internet
Author: User
Php simulates the return status of the post _ verification page (for example ). 1. access this page, which sets the returned Status header (HTTP1.1. $ code .. $ _ status [$ code]) copy the code as shown in figure 1. access the main file to access this page. This page sets the return Status header ('http/123') for this file based on the return results of the "verification page '. $ code. ''. $ _ status [$ code])

The code is as follows:


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 ',
=> 'Accessted ',
=> 'Non-Authoritative information ',
=> 'No content ',
=> 'Reset content ',
=> 'Partial content ',
// Redirection 3xx
=> 'Multiple choices ',
=> 'Moved Permanently ',
=> 'Moved Temporarily ', // 1.1
=> 'See Other ',
=> 'Not modified ',
=> 'Use proxy ',
/// 306 is deprecated but reserved
=> 'Temporary redirect ',
// Client Error 4xx
=> 'Bad request ',
=> 'Authorized ',
=> 'Payment required ',
=> 'Forbidden ',
=> 'Not Found ',
=> 'Method Not allowed ',
=> 'Not acceptable ',
=> 'Proxy Authentication required ',
=> 'Request timeout ',
=> 'Conflict ',
=> 'Gione ',
=> 'Length required ',
=> 'Precondition failed ',
=> 'Request Entity Too Large ',
=> 'Request-URI Too long ',
=> 'Unsupported Media type ',
=> 'Requested Range Not satisfiable ',
=> 'Pectation failed ',
// Server Error 5xx
=> 'Internal Server error ',
=> 'Not implemented ',
=> 'Bad Gateway ',
=> 'Service unavailable ',
=> 'Gateway timeout ',
=> 'Http Version Not ororted ',
=> '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); // sets the URL

Curl_setopt ($ curl, CURLOPT_HEADER, 1); // Get the Header
Curl_setopt ($ curl, CURLOPT_NOBODY, true); // we just need Head
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); // save the data to a string. don't output it to the screen.
$ Data = curl_exec ($ curl); // start execution ~
$ HttpCode = curl_getinfo ($ curl, CURLINFO_HTTP_CODE); // I know the HTTPSTAT code ~
Curl_close ($ curl); // when used up, remember to turn it 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 ."
";
Echo "detection results
";
For ($ I = $ start; $ I <= $ end; $ I ++)
{
$ Url = ResetUrl ($ UrlArr [$ I]);
$ State = GetStatusCode ($ url );
Echo "". $ state. "=>". $ url ."";
If ($ state! = "200 ")
{
Echo "access error!
";
Send_http_status ($ state );

// Send an email
Require ("Mail. php ");
$ MailPara ["Subject"] = "website monitoring result ";
$ MailPara ["Body"] = "error message: Status->". $ state ."
Address: ". $ url;
SendResultMail ($ MailPara );

Break;
}
Echo"
";
}
$ ETime = date ("Y/m/d H: m: s ");

Echo "end time". $ eTime ."
";
}

}
ShowStateInfo ($ UrlArr, $ MailPara );
?>


2. email

The code is 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 "failed to send the email.

";
Echo "error cause:". $ mail-> ErrorInfo ."
";
Exit;
}

Echo "email sent successfully
";
}


3. configuration file

The code is as follows:


$ 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"
);

// Send related information by email
$ MailPara = array (
"CharSet" => "GB2312 ",
"Host" => "smtp.exmail.qq.com", // email service address
"Port" => 25,

"FromMail" => "fdsafdsafd@fdasfds.com", // sender email address
"FromMailPassword" => "**********", // sender's email password
"FromMailName" => "detection", // sender's name

"To" => array (
Array (
"ToMail" => "defdafdsafdsafdf@qq.com", // recipient email address
"ToMailName" => "bqq", // recipient's name
),
Array (
"ToMail" => "abfdsafdsafdsafc@gmail.com", // recipient email address
"ToMailName" => "agmail", // recipient's name
)
),

"Subject" => "", // mail title
"Body" => "", // mail content
"AltBody" => "additional information" // additional information, which can be omitted
);

?>


"Phpmailer ", Click to download

Response header ('http/1.1 '. $ code. ''. $ _ status [$ code]) code such...

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.