[php]view plain
copy
header(
'content-type:text/html;charset=utf-8'
);
function
curlpost(
$url
,$data
,$method
)
curl_setopt($ch
, curlopt_returntransfer, true);
$tmpinfo
= curl_exec(
$ch);
//6.執行
if(curl_errno(
$ch))
curl_close($ch
);//8.關閉
return
$tmpinfo
;
}
$data
=array
('name'
=>
'1234'
);
$url
="";
$method
="get"
; //post或者get
$file
=curlpost(
$url
,$data
,$method
);
$file
=mb_convert_encoding(
$file
,'utf-8'
,'gbk'
);
echo
$file
;
以下是模擬登陸的**
[php]view plain
copy
<?php
$cookie_file
= tempnam(
'./temp'
,'cookie'
);
function
weixinpost(
$url
,$data
,$method
,$setcooke
=false,
$cookie_file
=false) if(
$setcooke
==true)else
curl_setopt($ch
, curlopt_returntransfer, true);
$tmpinfo
= curl_exec(
$ch);
//6.執行
if(curl_errno(
$ch))
curl_close($ch
);//8.關閉
return
$tmpinfo
;
}
$data
=array
('username'
=>
'***'
,'password'
=>
'***'
);
$url
="";
$method
="post"
;
$file
=weixinpost(
$url
,$data
,$method
,true,
$cookie_file
);
echo
$file
;
$url
="";
$method
="get"
;
$file
=weixinpost(
$url
,$data
,$method
,false,
$cookie_file
);
echo
$file
;
?>
網上的很多模擬登入程式,大都是通過服務程式apache之類的執行,獲取到驗證碼之後顯示在網頁上,然後填上再post出去
本文提供了乙個程式例項,思路就是獲取到驗證碼之後把驗證碼儲存為乙個,然後程式休眠20秒,在20秒之後由使用者手動檢視,並把驗證碼填寫到code.txt檔案中,20秒休眠完成後,程式會讀code.txt的驗證碼,這樣再帶著驗證碼進行登入操作。具體**如下:
[php]view plain
copy
/*** 模擬登入
*///初始化變數
$cookie_file
= "tmp.cookie"
; $login_url
= ""
; $verify_code_url
= ""
; echo
"正在獲取cookie...\n"
; $curlj
= curl_init();
$timeout
= 5;
curl_setopt($curl
, curlopt_url,
$login_url
);
curl_setopt($curl
, curlopt_returntransfer, 1);
curl_setopt($curl
, curlopt_connecttimeout,
$timeout
);
curl_setopt($curl
,curlopt_cookiejar,
$cookie_file
); //獲取cookie並儲存
$contents
= curl_exec(
$curl
);
curl_close($curl
);
echo
"cookie獲取完成,正在取驗證碼...\n"
; //取出驗證碼
"驗證碼取出完成,正在休眠,20秒內請把驗證碼填入code.txt並儲存\n"
; //停止執行20秒
sleep(20);
echo
"休眠完成,開始取驗證碼...\n"
; $code
= file_get_contents
("code.txt"
);
echo
"驗證碼成功取出:$code\n"
; echo
"正在準備模擬登入...\n"
; $post
= "username=maben&pwd=hahahaha&verifycode=$code"
; $curl
= curl_init();
curl_setopt($curl
, curlopt_url,
$url
);
curl_setopt($curl
, curlopt_header, false);
curl_setopt($curl
, curlopt_returntransfer,1);
curl_setopt($curl
, curlopt_postfields,
$post
);
curl_setopt($curl
, curlopt_cookiefile,
$cookie_file
);
$result
=curl_exec(
$curl
);
curl_close($curl
);
//這一塊根據自己抓包獲取到的**上的資料來做判斷
if(substr_count(
$result
,"登入成功"
))else
//ok,開始做你想做的事吧。。。。。
CURL模擬登陸
created by phpstorm.user machenike date 2016 7 8 time 13 40 header content type text html charset utf 8 set time limit 0 關閉請求時間 cookie tempnam cookie ...
curl模擬登陸
稍微有點水平的一看就能明白我講的是啥吧.有的內容略.這個東西不能留下能直接用的.培養大家的開發能力.去掉了關鍵注釋 name test.php date thu jan 24 00 24 20 cst 2008 author 馬永佔 myz link header content type text...
Shell 利用 curl 模擬登陸
b 引數 指定使用cookie檔案 c是往cookie檔案中寫cookie d 是指定此次登入所需的引數,通過httpfox檢視 l 指定頁面自動跳轉 curl c ck.txt user agent mozilla 4.0 d username password server id 1 submi...