phpcurl模擬登錄
Ⅰ php CURL 實現 模擬登陸 為何目標網站沒有登陸的反應呢 高手請進
1、表單登陸地址不對
2、表單名不對,名字是username 和 password 沒有ls
<?php
$curl=curl_init();
$cookie_jar=tempnam('./tmp','cookie');
curl_setopt($curl,CURLOPT_URL,'http://bbs.miaozhan360.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes');//這里寫上處理登錄的界面
curl_setopt($curl,CURLOPT_POST,1);
$request='username=wonderwiller&password=wonderwiller';
curl_setopt($curl,CURLOPT_POSTFIELDS,$request);//傳遞數據
curl_setopt($curl,CURLOPT_COOKIEJAR,$cookie_jar);//把返回來的cookie信息保存在$cookie_jar文件中
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);//設定返回的數據是否自動顯示
curl_setopt($curl,CURLOPT_HEADER,false);//設定是否顯示頭信息
curl_setopt($curl,CURLOPT_NOBODY,false);//設定是否輸出頁面內容
$r=curl_exec($curl);//返回結果
echo$r;
curl_close($curl);//關閉
$curl2=curl_init();
curl_setopt($curl2,CURLOPT_URL,'http://bbs.miaozhan360.com/forum.php');//登陸後要從哪個頁面獲取信息
curl_setopt($curl2,CURLOPT_HEADER,false);
curl_setopt($curl2,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl2,CURLOPT_COOKIEFILE,$cookie_jar);
$content=curl_exec($curl2);
echo$content;
?>
Ⅱ 如何判斷php中curl模擬登陸是否成功
/**
* 模擬登錄
*/
//初始化變數
$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";
//取出驗證碼
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $verify_code_url);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$img = curl_exec($curl);
curl_close($curl);
$fp = fopen("verifyCode.jpg","w");
fwrite($fp,$img);
fclose($fp);
echo "驗證碼取出完成,正在休眠,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,"登錄成功")){
echo "登錄成功\n";
}else{
echo "登錄失敗\n";
exit;
}
Ⅲ 我想用PHP的curl做一個帶驗證碼的模擬登陸,可是我不太清楚header中應包含什麼
模擬瀏覽器登陸應用開發,最關鍵的地方是突破登陸驗證。CURL技術不只支持http,還支持https。區別就在多了一層SSL加密傳輸。
如果是要登陸https網站,php記得要支持openssl。還是先拿一個例子來分析。
Ⅳ PHP的curl模擬·登錄老是失敗出現了405錯誤
405 是指請求的 URL 不支持請求的方法, htm(除偽靜態)是靜態頁面,是只能使用 get 方法的,而你要登錄,要用post,而你這里也確實是用的 post,那麼我覺得你應該是 URL 取錯了。像這種 post 的地址都要是有程序處理的,你再回去看看原來頁面中 form 上的 action 地址吧
Ⅳ php curl 無法實現模擬登陸
<?php
$discuz_url = 'http://127.0.0.1/discuz/';//論壇地址
$login_url = $discuz_url .'logging.php?action=login';//登錄頁地址
$post_fields = array();
//以下兩項不需要修改
$post_fields['loginfield'] = 'username';
$post_fields['loginsubmit'] = 'true';
//用戶名和密碼,必須填寫
$post_fields['username'] = 'tianxin';
$post_fields['password'] = '111111';
//安全提問
$post_fields['questionid'] = 0;
$post_fields['answer'] = '';
//@todo驗證碼
$post_fields['seccodeverify'] = '';
//獲取表單FORMHASH
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
preg_match('/<input\s*type="hidden"\s*name="formhash"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}
//POST數據,獲取COOKIE,cookie文件放在網站的temp目錄下
$cookie_file = tempnam('./temp','cookie');
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
//取到了關鍵的cookie文件就可以帶著cookie文件去模擬發帖,fid為論壇的欄目ID
$send_url = $discuz_url."post.php?action=newthread&fid=2";
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
//這里的hash碼和登陸窗口的hash碼的正則不太一樣,這里的hidden多了一個id屬性
preg_match('/<input\s*type="hidden"\s*name="formhash"\s*id="formhash"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
if(!empty($matches)) {
$formhash = $matches[1];
} else {
die('Not found the forumhash.');
}
$post_data = array();
//帖子標題
$post_data['subject'] = 'test2';
//帖子內容
$post_data['message'] = 'test2';
$post_data['topicsubmit'] = "yes";
$post_data['extra'] = '';
//帖子標簽
$post_data['tags'] = 'test';
//帖子的hash碼,這個非常關鍵!假如缺少這個hash碼,discuz會警告你來路的頁面不正確
$post_data['formhash']=$formhash;
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_REFERER, $send_url); //偽裝REFERER
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$contents = curl_exec($ch);
curl_close($ch);
//清理cookie文件
unlink($cookie_file);
?>
Ⅵ php curl 模擬登陸的問題驗證碼怎麼破
網路技術飛速發展,紅黑較量也是日新月異,我們要想取得長久的勝利,就不能得過且過,想繞過一切驗證碼,是不可能實現的。
建議:
用curl模擬登陸頁面獲取驗證碼圖片,手工錄入
當然了,如果後台是你自己的就不要驗證碼就OK了,但這是個 個例,不是泛指,希望能幫到你。
Ⅶ php curl 模擬登錄 失敗不成功 高手來解救!
請使用SNOOPY,你網路一下就有下載地址了他是對CURL的封裝,大網站很多都用這個