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

首頁 > CMS > Discuz > 正文

php中用curl模擬登錄discuz以及模擬發帖

2024-09-11 09:02:40
字體:
來源:轉載
供稿:網友

本文章完美的利用了php的curl功能實現模擬登錄discuz以及模擬發帖,本教程供參考學習.

  1. <?php 
  2. $discuz_url = ‘http://localhost/klive/root/Discuz_X2.5_SC_GBK/’;//論壇地址 
  3. $login_url = $discuz_url .’member.php?mod=logging&action=login’;//登錄頁地址 
  4. $post_fields = array(); 
  5. //以下兩項不需要修改 
  6. $post_fields['loginfield'] = ‘username’; 
  7. $post_fields['loginsubmit'] = ‘true’; 
  8. //用戶名和密碼,必須填寫 
  9. $post_fields['username'] = ‘admin’; 
  10. $post_fields['password'] = ‘admin’; 
  11. //安全提問 
  12. $post_fields['questionid'] = 0; 
  13. $post_fields['answer'] = ”; 
  14. //@todo驗證碼 
  15. $post_fields['seccodeverify'] = ”; 
  16. //獲取表單FORMHASH 
  17. $ch = curl_init($login_url); 
  18. curl_setopt($ch, CURLOPT_HEADER, 0); 
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  20. $contents = curl_exec($ch); 
  21. curl_close($ch); 
  22. preg_match(‘/<inputs*type=”hidden”s*name=”formhash”s*value=”(.*?)”s*/>/i’, $contents
  23. $matches); 
  24. if(!emptyempty($matches)) { 
  25. $formhash = $matches[1]; 
  26. else { 
  27. die(‘Not found the forumhash.’); 
  28. //POST數據,獲取COOKIE,cookie文件放在網站的temp目錄下 
  29. $cookie_file = tempnam(‘./temp’,'cookie’); 
  30. $ch = curl_init($login_url); 
  31. curl_setopt($ch, CURLOPT_HEADER, 0); 
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  33. curl_setopt($ch, CURLOPT_POST, 1); 
  34. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
  35. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); 
  36. curl_exec($ch); 
  37. curl_close($ch); 
  38. //取到了關鍵的cookie文件就可以帶著cookie文件去模擬發帖,fid為論壇的欄目ID 
  39. $send_url = $discuz_url.”forum.php?mod=post&action=newthread&fid=2″; 
  40. $ch = curl_init($send_url); 
  41. curl_setopt($ch, CURLOPT_HEADER, 0); 
  42. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  43. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
  44. $contents = curl_exec($ch); 
  45. curl_close($ch); 
  46. //這里的hash碼和登陸窗口的hash碼的正則不太一樣,這里的hidden多了一個id屬性 
  47. preg_match(‘/<inputs*type=”hidden”s*name=”formhash”s*id=”formhash”s*value=”(.*?)”s*/>/i 
  48. ’, $contents$matches); 
  49. if(!emptyempty($matches)) { 
  50. $formhash = $matches[1]; 
  51. else { 
  52. die(‘Not found the forumhash.’); 
  53. $post_data = array(); 
  54. //帖子標題 
  55. $post_data['subject'] = ‘test2′; 
  56. //帖子內容 
  57. $post_data['message'] = ‘test2′; 
  58. $post_data['topicsubmit'] = “yes”; 
  59. $post_data['extra'] = ”; 
  60. //帖子標簽 
  61. $post_data['tags'] = ‘test’; 
  62. //帖子的hash碼,這個非常關鍵!假如缺少這個hash碼,discuz會警告你來路的頁面不正確 
  63. $post_data['formhash']=$formhash
  64. $ch = curl_init($send_url); 
  65. curl_setopt($ch, CURLOPT_REFERER, $send_url);       //偽裝REFERER 
  66. curl_setopt($ch, CURLOPT_HEADER, 0); 
  67. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); 
  68. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
  69. curl_setopt($ch, CURLOPT_POST, 1); 
  70. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
  71. $contents = curl_exec($ch); 
  72. curl_close($ch); 
  73. //清理cookie文件 
  74. unlink($cookie_file); 
  75. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昌邑市| 双柏县| 广西| 金乡县| 镇坪县| 莱阳市| 呈贡县| 乌兰察布市| 贺州市| 波密县| 阿拉善左旗| 那坡县| 蓬莱市| 涡阳县| 调兵山市| 苏州市| 秦安县| 重庆市| 汤原县| 寿光市| 开原市| 永修县| 台湾省| 连云港市| 邵阳市| 景洪市| 承德市| 阳原县| 朝阳区| 沙湾县| 会东县| 齐齐哈尔市| 财经| 高要市| 深圳市| 平和县| 荣昌县| 独山县| 姚安县| 蒲江县| 新田县|