/isU', $contents, $matches);
//echo"";
//print_r($matches);die;
if(!empty($matches)) {
$formhash = $matches[1];
} else {
// die('Not found the forumhash.');
}
return $formhash;
}
public function getcookie($login_url,$post){
$cookie_file = tempnam('./temp','cookie');
//print_r($cookie_file);die;
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
$this->cookie_file=$cookie_file;
return $cookie_file;
}
public function use_cookie($send_url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $send_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
//获得发帖页面的fromhash
preg_match_all('//isU',$contents,$matches);
if(!empty($matches)){
$formhash = $matches[1][0];
}else {
$formhash='';//没有
}
return $formhash;
}
public function post_newthread($send_url,$thread_data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $send_url);
curl_setopt($ch, CURLOPT_REFERER, $send_url);//伪装REFERER
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $thread_data);
$contents = curl_exec($ch);
curl_close($ch);
return 1;
}
}
//下面是代码例子*******************************************************************************
$rc= new discuz_post();
//登陆的地址
$login_url='http://bbs.phpchina.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes';
$theformhash= $rc->get_formhash($login_url);
//登陆部分需要发送的数据,这里处理没有验证码的
$login_array=array(
'username'=>'用户名',
'password'=>'密码',
'referer'=>'http://bbs.phpchina.com/',
'questionid'=>0,
'answer'=>'',
'seccodeverify'=>'',
'formhash'=>$theformhash,//这个貌似没有也可以发帖滴
);
//获得cookie文件
$the_cookie_file= $rc->getcookie($login_url,$login_array);
$send_url ='http://bbs.phpchina.com/forum.php?mod=post&action=newthread&fid=2&infloat=yes';
$thesendformhash= $rc->use_cookie($send_url);//利用cookie文件的
$post_array=array(
'subject' =>"发帖,发帖测试",//标题
'message' =>"内容噢噢噢噢噢噢噢噢",//要超过10个字,奶奶的
'topicsubmit' =>"yes",
'extra' => '',
'tags' => 'Curl',//帖子标签
'formhash'=>$thesendformhash,
);
$rc->post_newthread($send_url,$post_array);//发了一贴
echo"";
print_r($rc);
echo $theformhash;
echo $the_cookie_file;
echo $thesendformhash;
unlink($rc->cookie_file);//删除cookie文件,也可以不删除
echo"ok!";
?>
/isU', $contents, $matches);
//echo"";
//print_r($matches);die;
if(!empty($matches)) {
$formhash = $matches[1];
} else {
// die('Not found the forumhash.');
}
return $formhash;
}
public function getcookie($login_url,$post){
$cookie_file = tempnam('./temp','cookie');
//print_r($cookie_file);die;
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
$this->cookie_file=$cookie_file;
return $cookie_file;
}
public function use_cookie($send_url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $send_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
//获得发帖页面的fromhash
preg_match_all('//isU',$contents,$matches);
if(!empty($matches)){
$formhash = $matches[1][0];
}else {
$formhash='';//没有
}
return $formhash;
}
public function post_newthread($send_url,$thread_data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $send_url);
curl_setopt($ch, CURLOPT_REFERER, $send_url);//伪装REFERER
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $thread_data);
$contents = curl_exec($ch);
curl_close($ch);
return 1;
}
}
//下面是代码例子*******************************************************************************
$rc= new discuz_post();
//登陆的地址
$login_url='http://bbs.phpchina.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes';
$theformhash= $rc->get_formhash($login_url);
//登陆部分需要发送的数据,这里处理没有验证码的
$login_array=array(
'username'=>'用户名',
'password'=>'密码',
'referer'=>'http://bbs.phpchina.com/',
'questionid'=>0,
'answer'=>'',
'seccodeverify'=>'',
'formhash'=>$theformhash,//这个貌似没有也可以发帖滴
);
//获得cookie文件
$the_cookie_file= $rc->getcookie($login_url,$login_array);
$send_url ='http://bbs.phpchina.com/forum.php?mod=post&action=newthread&fid=2&infloat=yes';
$thesendformhash= $rc->use_cookie($send_url);//利用cookie文件的
$post_array=array(
'subject' =>"发帖,发帖测试",//标题
'message' =>"内容噢噢噢噢噢噢噢噢",//要超过10个字,奶奶的
'topicsubmit' =>"yes",
'extra' => '',
'tags' => 'Curl',//帖子标签
'formhash'=>$thesendformhash,
);
$rc->post_newthread($send_url,$post_array);//发了一贴
echo"";
print_r($rc);
echo $theformhash;
echo $the_cookie_file;
echo $thesendformhash;
unlink($rc->cookie_file);//删除cookie文件,也可以不删除
echo"ok!";
?>
0
0
用php_curl对discuzx 2.5模拟登陆,保存cookie,并进行发帖的类
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
本专题汇总了包子漫画官网和网页版入口,提供最新章节抢先看方法、正版免费阅读指南,以及稳定访问方式,帮助用户快速直达包子漫画页面,无广告畅享全集漫画内容。
47
2026.02.10
本专题汇总了MC.JS官网入口和网页版快速畅玩方法,提供免安装访问、不同版本(1.8.8、1.12.8)在线体验指南,以及正版网页端操作说明,帮助玩家轻松进入MC.JS世界,实现即时畅玩与高效体验。
33
2026.02.10
本专题汇总了谷歌邮箱网页版的最新登录入口和注册方法,详细提供官方账号快速访问方式、网页版操作教程及安全登录技巧,帮助用户轻松管理Gmail邮箱账户,实现高效、安全的邮箱使用体验。
25
2026.02.10
本专题全面汇总铁路12306订票、退票、改签及候补订单操作技巧,提供车厢座位分布参考、抢票攻略和高铁安检注意事项,帮助新手用户快速掌握高效购票与退改流程,提高出行效率和体验。
27
2026.02.10
本专题面向 AI 与数据科学开发者,系统讲解 TensorFlow 2 框架下深度学习模型的构建、训练、调优与部署。内容包括神经网络基础、卷积神经网络、循环神经网络、优化算法及模型性能提升技巧。通过实战项目演示,帮助开发者掌握从模型设计到上线的完整流程。
0
2026.02.10
本专题讲解 Vue 3 组合式 API 的核心概念与应用技巧,深入分析响应式系统、生命周期管理、组件设计与复用策略。通过完整项目案例,指导前端开发者实现高性能、结构清晰的 Vue 应用,提升开发效率与代码可维护性。
4
2026.02.10
本专题面向有 Go 基础的开发者,系统讲解微服务架构设计与 gRPC 的高效应用。内容涵盖服务拆分、RPC 通信、负载均衡、错误处理、服务注册与发现等关键技术。通过实战案例,帮助开发者搭建高性能、可扩展的 Go 微服务系统。
1
2026.02.10
本专题专注于 React 18 的高级开发技术,详细讲解 useState、useEffect、useReducer、useContext 等 Hooks 的使用技巧,以及 Redux、Zustand 等状态管理工具的集成与优化方法。通过真实案例,帮助前端开发者构建可维护、性能优良的现代 React 应用。
4
2026.02.10
本专题针对初中级 Node.js 开发者,系统讲解如何使用 Express 框架搭建高性能后端服务。内容包括路由设计、中间件开发、数据库集成、API 安全与异常处理,以及 RESTful API 的设计与优化。通过实际项目演示,帮助开发者快速掌握 Node.js 后端开发流程。
2
2026.02.10
热门下载
相关下载
精品课程
共11课时 | 3.1万人学习
共24课时 | 7.1万人学习
共12课时 | 2.7万人学习


