免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
!!!!! php 使用curl模擬登錄discuz以及模擬發(fā)帖 | SimonLeung's Blo...

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

本著共享的原則,我把自己測試成功的發(fā)帖代碼貼出來。不足的地方,希望大家指正。

 
01<div><?php
02$discuz_url ';//論壇地址
03$login_url $discuz_url .'logging.php?action=login';//登錄頁地址
04 
05$post_fields array();
06//以下兩項不需要修改
07$post_fields['loginfield'] = 'username';
08$post_fields['loginsubmit'] = 'true';
09//用戶名和密碼,必須填寫
10$post_fields['username'] = 'tianxin';
11$post_fields['password'] = '111111';
12//安全提問
13$post_fields['questionid'] = 0;
14$post_fields['answer'] = '';
15//@todo驗證碼
16$post_fields['seccodeverify'] = '';
17 
18//獲取表單FORMHASH
19$ch = curl_init($login_url);
20curl_setopt($ch, CURLOPT_HEADER, 0);
21curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
22$contents = curl_exec($ch);
23curl_close($ch);
24preg_match('/<input\s*type="hidden"\s*name="formhash"\s*value="(.*?)"\s*\/>/i'$contents$matches);
25if(!empty($matches)) {
26 $formhash $matches[1];
27else {
28 die('Not found the forumhash.');
29}
30 
31//POST數(shù)據(jù),獲取COOKIE,cookie文件放在網(wǎng)站的temp目錄下
32$cookie_file = tempnam('./temp','cookie');
33 
34$ch = curl_init($login_url);
35curl_setopt($ch, CURLOPT_HEADER, 0);
36curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
37curl_setopt($ch, CURLOPT_POST, 1);
38curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
39curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
40curl_exec($ch);
41curl_close($ch);
42 
43//取到了關鍵的cookie文件就可以帶著cookie文件去模擬發(fā)帖,fid為論壇的欄目ID
44$send_url $discuz_url."post.php?action=newthread&fid=2";
45 
46$ch = curl_init($send_url);
47curl_setopt($ch, CURLOPT_HEADER, 0);
48curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
49curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
50$contents = curl_exec($ch);
51curl_close($ch);
52 
53//這里的hash碼和登陸窗口的hash碼的正則不太一樣,這里的hidden多了一個id屬性
54preg_match('/<input\s*type="hidden"\s*name="formhash"\s*id="formhash"\s*value="(.*?)"\s*\/>/i'$contents$matches);
55if(!empty($matches)) {
56 $formhash $matches[1];
57else {
58 die('Not found the forumhash.');
59}
60 
61$post_data array();
62//帖子標題
63$post_data['subject'] = 'test2';
64//帖子內(nèi)容
65$post_data['message'] = 'test2';
66$post_data['topicsubmit'] = "yes";
67$post_data['extra'] = '';
68//帖子標簽
69$post_data['tags'] = 'test';
70//帖子的hash碼,這個非常關鍵!假如缺少這個hash碼,discuz會警告你來路的頁面不正確
71$post_data['formhash']=$formhash;
72 
73$ch = curl_init($send_url);
74curl_setopt($ch, CURLOPT_REFERER, $send_url);       //偽裝REFERER
75curl_setopt($ch, CURLOPT_HEADER, 0);
76curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
77curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
78curl_setopt($ch, CURLOPT_POST, 1);
79curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
80$contents = curl_exec($ch);
81curl_close($ch);
82 
83//清理cookie文件
84unlink($cookie_file);
85 
86?></div>
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
php curl_init函數(shù)用法
php獲取通過http協(xié)議post提交過來xml數(shù)據(jù)及解析xml
php curl實現(xiàn)get和post的代碼
關于php 接口問題(php接口主要也就是運用curl,curl函數(shù))
php中轉菜刀腳本過狗免殺
PHP curl提交參數(shù)到某個網(wǎng)址,然后獲取數(shù)據(jù)
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服