最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php通過curl模擬登陸DZ論壇

 更新時間:2015年05月11日 11:59:21   投稿:hebedich  
本文章來給各位同學介紹一下關于Php CURL模擬登陸論壇并采集數(shù)據(jù)實例,如果你對利用curl模擬登錄功能有興趣可進入?yún)⒖肌?/div>

libcurl同時也支持HTTPS認證、HTTP POST、HTTP PUT、 FTP 上傳(這個也能通過PHP的FTP擴展完成)、HTTP 基于表單的上傳、代理、cookies和用戶名+密碼的認證。

<?php 
$discuz_url = 'http://m.fzitv.net/';//論壇地址 
$login_url = $discuz_url .'login.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數(shù)據(jù),獲取COOKIE,cookie文件放在網(wǎng)站的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文件去模擬發(fā)帖,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); 
?>

以上所述就是本文的全部內容了,希望大家能夠喜歡。

相關文章

最新評論

柘城县| 格尔木市| 富平县| 仁寿县| 祥云县| 普安县| 天长市| 察隅县| 安康市| 阜城县| 积石山| 教育| 托克托县| 调兵山市| 晋江市| 桃园市| 沁源县| 隆化县| 突泉县| 宁夏| 呼伦贝尔市| 乌拉特中旗| 南充市| 安图县| 澄城县| 谷城县| 平遥县| 绥宁县| 鄂托克旗| 呈贡县| 云浮市| 建昌县| 康马县| 肇州县| 桂阳县| 东丽区| 吴堡县| 长垣县| 新和县| 历史| 正镶白旗|