国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

php中通過curl模擬登陸discuz論壇的實現(xiàn)代碼

2020-03-22 19:52:01
字體:
供稿:網(wǎng)友
  • libcurl同時也支持HTTPS認證、HTTP POST、HTTP PUT、 FTP 上傳(這個也能通過PHP的FTP擴展完成)、HTTP 基于表單的上傳、代理、cookies和用戶名+密碼的認證。

    php的curl真的是相當好用,網(wǎng)上一搜索相關(guān)文章都是關(guān)于curl模擬登陸的,很少人提供模擬discuz發(fā)貼的源碼

    <?php $discuz_url = 'http://www.lai18.com/';//論壇地址 $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('/<inputs*type="hidden"s*name="formhash"s*html' target='_blank'>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多了一個id屬性 preg_match('/<inputs*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'; //帖子內(nèi)容 $post_data['message'] = 'test2'; $post_data['topicsubmit'] = "yes"; $post_data['extra'] = ''; //帖子標簽 $post_data['tags'] = 'test'; //帖子的hash碼,這個非常關(guān)鍵!假如缺少這個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); ?>

    《CURL技術(shù)知識教程》系列技術(shù)教程整理

    http://blog.csdn.net/hello_katty/article/details/45557423

    PHP編程

    鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

  • 發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發(fā)表
    主站蜘蛛池模板: 汨罗市| 南安市| 哈巴河县| 阜南县| 平泉县| 龙川县| 浮山县| 大邑县| 都安| 错那县| 肥西县| 长沙市| 清水县| 合江县| 军事| 湖北省| 剑阁县| 嫩江县| 吉木乃县| 鄂尔多斯市| 蚌埠市| 增城市| 建昌县| 太白县| 棋牌| 广元市| 余姚市| 东阿县| 伊川县| 高邑县| 恩施市| 桐乡市| 会同县| 锦屏县| 宁城县| 武宁县| 社旗县| 张北县| 泌阳县| 大埔县| 会东县|