php 類比post_驗證頁面的返回狀態(執行個體講解)_PHP教程

來源:互聯網
上載者:User
1.主要檔案,訪問該頁面,該頁面根據“驗證頁面”的返回結果設定本檔案的返回狀態 header('HTTP/1.1 '.$code.' '.$_status[$code])
複製代碼 代碼如下:
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
=> 'See Other',
=> 'Not Modified',
=> 'Use Proxy',
// 306 is deprecated but reserved
=> 'Temporary Redirect',
// Client Error 4xx
=> 'Bad Request',
=> 'Unauthorized',
=> 'Payment Required',
=> 'Forbidden',
=> 'Not Found',
=> 'Method 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); //設定URL

curl_setopt($curl, CURLOPT_HEADER, 1); //擷取Header
curl_setopt($curl,CURLOPT_NOBODY,true); //Body就不要了吧,我們只是需要Head
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //資料存到成字串吧,別給我直接輸出到螢幕了
$data = curl_exec($curl); //開始執行啦~
$HttpCode =curl_getinfo($curl,CURLINFO_HTTP_CODE); //我知道HTTPSTAT碼哦~
curl_close($curl); //用完記得關掉他
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 "開始時間".$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 "郵件發送失敗.

";
echo "錯誤原因: " . $mail->ErrorInfo ."
";
exit;
}

echo "郵件發送成功
";
}

3.設定檔
複製代碼 代碼如下:
$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"
);

//郵箱發送相關資訊
$MailPara=array(
"CharSet"=> "GB2312",
"Host"=> "smtp.exmail.qq.com", // 郵箱服務地址
"Port"=>25,

"FromMail"=> "fdsafdsafd@fdasfds.com", // 寄件者郵箱地址
"FromMailPassword"=> "*********", // 寄件者郵箱密碼
"FromMailName"=> "檢測", //寄件者稱呼

"To"=>array(
array(
"ToMail"=>"defdafdsafdsafdf@qq.com", //收件者郵箱地址
"ToMailName"=> "bqq", //收件者稱呼
),
array(
"ToMail"=>"abfdsafdsafdsafc@gmail.com", //收件者郵箱地址
"ToMailName"=> "agmail", //收件者稱呼
)
),

"Subject"=> "", //郵件標題
"Body"=> "", //郵件內容
"AltBody"=> "附加資訊" //附加資訊,可以省略
);

?>

郵件主要使用"phpmailer",點擊下載

http://www.bkjia.com/PHPjc/824912.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/824912.htmlTechArticle1.主要檔案,訪問該頁面,該頁面根據“驗證頁面”的返回結果設定本檔案的返回狀態 header('HTTP/1.1 '.$code.' '.$_status[$code]) 複製代碼 代碼如...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.