php 模拟post_验证页面的返回状态(实例讲解)

2015-01-24信息快讯网

php模拟post_验证页面的返回状态(实例讲解)。需要的朋友可以过来参考下,希望对大家有所帮助

1.主要文件,访问该页面,该页面根据“验证页面”的返回结果设置本文件的返回状态 header('HTTP/1.1 '.$code.' '.$_status[$code])

<?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 => '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."<br/>"; echo "检测结果<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'>本条访问出错!</span><br/>"; send_http_status($state);

//发邮件 require("Mail.php"); $MailPara["Subject"]="网站监控结果"; $MailPara["Body"]="错误信息:状态-><span style='color:red;font-weight:bold'>".$state."</span><br/>地址:".$url; SendResultMail($MailPara);

break; } echo "<br/>"; } $eTime=date("Y/m/d H:m:s");

echo "结束时间".$eTime."<br/>"; }

} 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 "邮件发送失败. <p>"; echo "错误原因: " . $mail->ErrorInfo ."<br/>"; exit; }

echo "邮件发送成功<br/>"; }


3.配置文件
<?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"
    );

//邮箱发送相关信息 $MailPara=array( "CharSet"=> "GB2312", "Host"=> "smtp.exmail.qq.com", // 邮箱服务地址 "Port"=>25,

"FromMail"=> "[email protected]", // 发件人邮箱地址 "FromMailPassword"=> "*********", // 发件人邮箱密码 "FromMailName"=> "检测", //发件人称呼 "To"=>array( array( "ToMail"=>"[email protected]", //收件人邮箱地址 "ToMailName"=> "bqq", //收件人称呼 ), array( "ToMail"=>"[email protected]", //收件人邮箱地址 "ToMailName"=> "agmail", //收件人称呼 ) ),

"Subject"=> "", //邮件标题 "Body"=> "", //邮件内容 "AltBody"=> "附加信息" //附加信息,可以省略 );

?>


邮件主要使用"phpmailer",点击下载

一个严格的PHP Session会话超时时间设置方法
PHP小教程之实现链表
浅谈Eclipse PDT调试PHP程序
教你如何在CI框架中使用 .htaccess 隐藏url中index.php
PHP、Nginx、Apache中禁止网页被iframe引用的方法
PHP防止post重复提交数据的简单例子
PHP函数分享之curl方式取得数据、模拟登陆、POST数据
windwos下使用php连接oracle数据库的过程分享
PHP函数strip_tags的一个bug浅析
PHP中spl_autoload_register()和__autoload()区别分析
PHP中把stdClass Object转array的几个方法
smarty模板中使用get、post、request、cookies、session变量的方法
通过curl模拟post和get方式提交的表单类
php过滤所有恶意字符(批量过滤post,get敏感数据)
php加密解密函数authcode的用法详细解析
php操作mysqli(示例代码)
php session_start()出错原因分析及解决方法
php 强制下载文件实现代码
php获取qq用户昵称和在线状态(实例分析)
php获取数组长度的方法(有实例)
PHP字符串长度计算 - strlen()函数使用介绍
php mysql_real_escape_string函数用法与实例教程
php中利用str_pad函数生成数字递增形式的产品编号
Zend studio文件注释模板设置方法
php strrpos()与strripos()函数
JoshChen_web格式编码UTF8-无BOM的小细节分析
JoshChen_php新手进阶高手不可或缺的规范介绍
php中用socket模拟http中post或者get提交数据的示例代码
解析php做推送服务端实现ios消息推送
php获取$_POST同名参数数组的实现介绍
解析curl提交GET,POST,Cookie的简单方法
使用PHP接收POST数据,解析json数据
php 模拟POST提交的2种方法详解
©2014-2024 dbsqp.com