php 模拟post_验证页面的返回状态(实例讲解)
php  /  管理员 发布于 7年前   376
1.主要文件,访问该页面,该页面根据“验证页面”的返回结果设置本文件的返回状态 header('HTTP/1.1 '.$code.' '.$_status[$code]) include("CheckConfig.php"); function send_http_status($code) { function GetStatusCode($url) curl_setopt($curl, CURLOPT_HEADER, 1); //获取Header function ResetUrl($url) function ShowStateInfo($UrlArr,$MailPara) $start=$start-1; if($start<0) if($start>=0 && $start<$count) if($end<$start) //发邮件 break; echo "结束时间".$eTime." } $mail = new PHPMailer(); $mail->SMTPAuth = true; $mail->Username = $MailPara["FromMail"]; foreach($MailPara["To"] as $toMail) $mail->Subject = $MailPara["Subject"]; if(!$mail->Send()) "; echo "邮件发送成功 //邮箱发送相关信息 "FromMail"=> "[email protected]", // 发件人邮箱地址 "To"=>array( "Subject"=> "", //邮件标题 ?>
ini_set('max_execution_time', 120);
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]);
}
}
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); //设置URL
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;
}
{
if(strpos($url,"?")>0)
$url.="&rnd";
else
$url.="?rnd";
$url.=rand();
return $url;
}
{
$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;
}
$end=$end-1;
{
$start=0;
}
{
if($end>=$count)
{
$end=$count-1;
}
{
$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);
}
echo "
";
}
$eTime=date("Y/m/d H:m:s");
";
}
ShowStateInfo($UrlArr,$MailPara);
?>
2.邮件
复制代码 代码如下:
function SendResultMail($MailPara)
{
require("phpmailer/class.phpmailer.php");
$mail->CharSet = $MailPara["CharSet"];
$mail->IsSMTP();
$mail->Host = $MailPara["Host"];
$mail->Port = $MailPara["Port"];
$mail->Password = $MailPara["FromMailPassword"];
$mail->From = $MailPara["FromMail"];
$mail->FromName = $MailPara["FromMailName"];
{
$mail->AddAddress($toMail["ToMail"], $toMail["ToMailName"]);
}
$mail->Body = $MailPara["Body"];
$mail->AltBody = $MailPara["AltBody"];
{
echo "邮件发送失败.
echo "错误原因: " . $mail->ErrorInfo ."
";
exit;
}
";
}
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,
"FromMailPassword"=> "*********", // 发件人邮箱密码
"FromMailName"=> "检测", //发件人称呼
array(
"ToMail"=>"[email protected]", //收件人邮箱地址
"ToMailName"=> "bqq", //收件人称呼
),
array(
"ToMail"=>"[email protected]", //收件人邮箱地址
"ToMailName"=> "agmail", //收件人称呼
)
),
"Body"=> "", //邮件内容
"AltBody"=> "附加信息" //附加信息,可以省略
);
邮件主要使用"phpmailer",点击下载您可能感兴趣的文章:
上一条:
php加密解密函数authcode的用法详细解析
下一条:
php操作mysqli(示例代码)
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号