php curl_setopt 登录 获取数据
登录 :以51啦统计数据为例
$cookfile = dirname(__FILE__).'/cookie.txt'; $ip=$_SERVER['SERVER_ADDR']; $uname="帐号"; $upass="密码"; // 设置URL和相应的选项 $HTTP_REQUEST_HEADER = array( "method" => "POST", "timeout" => 30, "Content-Type" => "application/x-www-form-urlencoded; charset=gb2312", "Referer" => "https://www.51.la/user/notice.asp", "Client-IP" => $ip, "X-Forwarded-For" => $ip, "Host" => "https://www.51.la/" ); $url = "https://www.51.la/login.asp"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //这行是设定curl是否跟随header发送的location,重要 curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_HTTPHEADER, $HTTP_REQUEST_HEADER); curl_setopt($ch, CURLOPT_POSTFIELDS, "uname=$uname&upass=$upass"); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookfile); // 保存cookie //curl_setopt($ch, CURLOPT_COOKIEFILE, $cookfile); // 发送 cookie curl_setopt($ch, CURLOPT_COOKIESESSION, 1); //以下为SSL设置 //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); $res = curl_exec($ch); echo curl_error($ch); curl_close($ch); if($res===false){ exit('false'); }elseif(strpos($res,$uname)>0){//查找用户名是否存在,存在则登录正确 echo '登录成功'; }else{ echo $res; }
获取统计信息:
$cookfile = dirname(__FILE__).'/cookie.txt';
$ip=$_SERVER['SERVER_ADDR'];
// 设置URL和相应的选项
$HTTP_REQUEST_HEADER = array(
"method" => "POST",
"timeout" => 30,
"Content-Type" => "application/x-www-form-urlencoded; charset=gb2312",
"Referer" => "https://www.51.la/user/notice.asp",
"Client-IP" => $ip,
"X-Forwarded-For" => $ip,
"Host" => "https://www.51.la/"
);
$url = "https://www.51.la/report/1_main.asp?id=2157050";
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //这行是设定curl是否跟随header发送的location,重要
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookfile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookfile); // 保存cookie
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
$res = curl_exec($ch1);
//关闭cURL资源,并且释放系统资源
curl_close($ch1);
if($html===false){
exit('false');
}
$html = str_replace(array("\r", "\n"), '', $html);
$html=cut_html($html,'<!--Ajiang Stat 2.0--><img','</div><div GB2312//IGNORE","UTF-8",$html);
$html=str_replace(array(' ',' '),'',$html);
preg_match_all('/\>(.*)IP/i', $html, $a);
$ip=$a[1];
preg_match_all('/IP\/(.*)UV\//i', $html, $a);
$uv=$a[1];
preg_match_all('/pv"\/\>(.*)PV/i', $html, $a);
$pv=$a[1];
最后更新:2017-04-03 22:15:26
上一篇:
我国首份IP地理信息标准库发布
下一篇:
Oracle中登陆时报ORA-28000: the account is locked-的错
阿里云(ECS+RDS)部署PHP+MySQL网站初探
C#委托基础9——Invoke与委托
万维网之父获2016年图灵奖,专访Tim Berners-Lee: 我创建万维网的初衷
100TB级, 日增量1TB, OLTP OLAP混合场景数据库设计方向
Print2Flash出现"System Error. Code:1722. RPC服务器不可用."错误解决办法
系统架构-性能篇章1(应用系统性能1)
民宿安全问题亟待解决 智能家居给你支招
用机器学习的经验指导人生:如何实现学习效率最大化
只需七步就能掌握Python数据准备
puts 和 printf %s【gets 和 %s姐妹篇】