一、定義cookie儲存路徑
必須使用絕對路徑
$cookie_jar = dirwww.cppcns.comname(__file__)."/pic.cookie";
二、獲取cookie
將cookie存入檔案
$url = "";
$ch = curl_init();
curvwakjkvgnl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_cookiejar, $cookie_jar);
$content = curl_execwww.cppcns.com($c程式設計客棧h);
curl_close($ch);
三、模擬瀏覽器獲取驗證碼
該伺服器驗證碼有漏洞,可以自己指定
取出cookie,一起提交給伺服器,讓伺服器以為是瀏覽器開啟登陸頁面
$ch = curl_init();
curl_setopt($ch, curlopt_url, 'getcheckpic.action?rand=6836.185874812305');
curl_setopt($ch, curlopt_cookiefile, $cookie_jar);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, 1);
$ret = curl_exec($ch);
curl_close($ch);
四、post提交
$post = "name=2&usertype=1&passwd=asdf&logintype=1&rand=6836&imagefield.x=25&imagefield.y=7";
$ch = curl_init();
curl_setopt($ch, curlopt_url, "loginstudent.action");
curl_setopt($ch, curlopt_header, false
curl_setopt($ch, curlopt_returntransfer,1);
curl_setopt($ch, curlopt_postfields, $post);
curl_setopt($ch, curlopt_cookiefile, $cookie_jar);
$result=curl_exec($ch);
curl_close($ch);
五、到指定頁面獲取資料
$ch = curl_init();
curl_setopt($ch, curlopt_url, "accountcarduser.action");
curl_setopt($ch, curlopt_header, false);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer,0);
curl_setopt($ch, curlopt_cookiefile, $cookie_jar);
$html=curl_exec($ch);
// var_dump($html);
curl_close($ch);
本文標題: php如何獲取cookie並實現模擬登入
本文位址:
php設定和獲取cookie
setcookie mycookie value 函式原型 int setcookie string name,string value,int expire,string path,string domain,int secure 刪除cookie 1 呼叫只帶有name引數的setcookie ...
php設定和獲取cookie
setcookie mycookie value 函式原型 int setcookie string name,string value,int expire,string path,string domain,int secure 刪除cookie 1 呼叫只帶有name引數的setcookie ...
PHP獲取Cookie模擬登入
一 定義cookie儲存路徑 必須使用絕對路徑 cookie jar dirname file pic.cookie 二 獲取cookie 將cookie存入檔案 url ch curl init curl setopt ch,curlopt url,url curl setopt ch,curlo...