天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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

libcurl同時(shí)也支持HTTPS認(rèn)證、HTTP POST、HTTP PUT、 FTP 上傳(這個(gè)也能通過php的FTP擴(kuò)展完成)、HTTP 基于表單的上傳、代理、cookies和用戶名+密碼的認(rèn)證。
php的curl真的是相當(dāng)好用,網(wǎng)上一搜索相關(guān)文章都是關(guān)于curl模擬登陸的,很少人提供模擬discuz發(fā)貼的源碼。
復(fù)制代碼 代碼如下:
<?php
$discuz_url = 'http://127.0.0.1/discuz/';//論壇地址
$login_url = $discuz_url .'logging.php?action=login';//登錄頁(yè)地址

$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ì)警告你來路的頁(yè)面不正確
$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);
?>

php技術(shù)php中通過curl模擬登陸discuz論壇的實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 99无人区码一码二码三 | 精品日产1区2卡三卡麻豆 | 国产免费人成在线看视频 | 嫩草伊人久久精品少妇AV网站 | 亚洲在线国产日韩欧美 | 快播在线电影网站 | 涩涩在线视频 | 中文无码字慕在线观看 | 曰批视频免费40分钟不要钱 | 色婷婷五月综合中文字幕 | 久久偷拍国2017 | 羞羞麻豆国产精品1区2区3区 | 99久久99久久久99精品齐 | 三八成人网 | 为什么丈夫插我我却喜欢被打着插 | 国产A级毛片久久久久久久 国产a级黄色毛片 | 久久久精品久久久久特色影视 | 亚洲国产综合久久久无码色伦 | 色综合五月激情综合色一区 | 在线观看视频国产 | 久久在精品线影院精品国产 | 欧美日韩另类在线专区 | 国产在线观看码高清视频 | 国产亚洲欧美日韩综合综合二区 | 女教师公车痴汉在线播放 | 色99久久久久高潮综合影院 | 午夜深情在线观看免费 | 无码欧美XXXXX在线观看裸 | 伊人国产在线播放 | 肉蒲团从国内封禁到日本成经典 | 百性阁综合社区 | 无码骚夜夜精品 | 涩涩视频下载 | 亚洲精品线在线观看 | 日本漫画之无彩翼漫画 | 国产亚洲精品久久久999密臂 | 花蝴蝶高清在线视频免费观看 | 黑人巨大两根一起挤进欧美 | 人妻满熟妇AV无码区国产 | 乐乐亚洲精品综合影院 | 精品亚洲国产成AV人片传媒 |