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姐妹篇】