php通過curl模擬登陸DZ論壇
更新時(shí)間:2015年05月11日 11:59:21 投稿:hebedich
本文章來給各位同學(xué)介紹一下關(guān)于Php CURL模擬登陸論壇并采集數(shù)據(jù)實(shí)例,如果你對(duì)利用curl模擬登錄功能有興趣可進(jìn)入?yún)⒖肌?/div>
libcurl同時(shí)也支持HTTPS認(rèn)證、HTTP POST、HTTP PUT、 FTP 上傳(這個(gè)也能通過PHP的FTP擴(kuò)展完成)、HTTP 基于表單的上傳、代理、cookies和用戶名+密碼的認(rèn)證。
<?php $discuz_url = 'http://chabaoo.cn/';//論壇地址 $login_url = $discuz_url .'login.php?action=login';//登錄頁地址 $post_fields = array(); //以下兩項(xiàng)不需要修改 $post_fields['loginfield'] = 'username'; $post_fields['loginsubmit'] = 'true'; //用戶名和密碼,必須填寫 $post_fields['username'] = 'tianxin'; $post_fields['password'] = '111111'; //安全提問 $post_fields['questionid'] = 0; $post_fields['answer'] = ''; //@todo驗(yàn)證碼 $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); //取到了關(guān)鍵的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多了一個(gè)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(); //帖子標(biāo)題 $post_data['subject'] = 'test2'; //帖子內(nèi)容 $post_data['message'] = 'test2'; $post_data['topicsubmit'] = "yes"; $post_data['extra'] = ''; //帖子標(biāo)簽 $post_data['tags'] = 'test'; //帖子的hash碼,這個(gè)非常關(guān)鍵!假如缺少這個(gè)hash碼,discuz會(huì)警告你來路的頁面不正確 $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); ?>
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
您可能感興趣的文章:
- php實(shí)現(xiàn)模擬登陸方正教務(wù)系統(tǒng)抓取課表
- PHP函數(shù)分享之curl方式取得數(shù)據(jù)、模擬登陸、POST數(shù)據(jù)
- PHP實(shí)現(xiàn)微信模擬登陸并給用戶發(fā)送消息的方法【文字,圖片,圖文】
- php模擬登陸的實(shí)現(xiàn)方法分析
- php中通過curl模擬登陸discuz論壇的實(shí)現(xiàn)代碼
- php 論壇采集程序 模擬登陸,抓取頁面 實(shí)現(xiàn)代碼
- PHP簡單實(shí)現(xiàn)模擬登陸功能示例
- php實(shí)現(xiàn)微信模擬登陸、獲取用戶列表及群發(fā)消息功能示例
- PHP 模擬登陸MSN并獲得用戶信息
- PHP模擬登陸163郵箱發(fā)郵件及獲取通訊錄列表的方法
- PHP 模擬登陸功能實(shí)例詳解
相關(guān)文章
thinkPHP+LayUI 流加載實(shí)現(xiàn)功能
這篇文章主要介紹了thinkPHP+LayUI 流加載實(shí)現(xiàn)功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09php 解決舊系統(tǒng) 查出所有數(shù)據(jù)分頁的類
不同之處在于 沒有實(shí)現(xiàn)分頁的系統(tǒng), 默認(rèn)全部查出來 現(xiàn)在就要不能動(dòng)后臺(tái)的基礎(chǔ)上進(jìn)行操作 可以采用 相應(yīng)的 如下 代碼2012-08-08Laravel5.2使用Captcha生成驗(yàn)證碼實(shí)現(xiàn)登錄(session巨坑)
這篇文章主要介紹了Laravel5.2使用Captcha生成驗(yàn)證碼(session巨坑),需要的朋友可以參考下2018-01-01Laravel中9個(gè)不經(jīng)常用的小技巧匯總
這篇文章主要給大家總結(jié)介紹了關(guān)于Laravel中9個(gè)不經(jīng)常用的小技巧,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Laravel具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04