/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工具
相关专题
从零到实战:Python 编程系统入门专题
本专题面向零编程基础及初学者,系统讲解 Python 编程语言的核心知识与实战技巧。内容涵盖 Python 基础语法、数据结构、函数与模块、常用标准库、简单算法思维,以及真实应用场景下的小项目实战。通过循序渐进的学习路径,帮助读者快速建立编程思维,掌握 Python 在数据处理、自动化脚本及日常开发中的实际应用能力,为后续深入学习 Web 开发、数据分析或人工智能打下坚实基础。
10
2026.01.05
Excel制作交互图表的方法 Excel交互式的图表教程大全
Excel交互式图表可通过四种方法实现:一、用切片器控制数据透视图;二、结合下拉列表与INDEX-MATCH动态引用;三、用选项按钮绑定图表系列;四、利用动态命名区域配合OFFSET函数。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。
330
2026.01.04
热门下载
相关下载
精品课程
相关推荐
/
热门推荐
/
最新课程
黑马云课堂mongodb实操视频教程
共11课时 | 3.1万人学习
MySQL优化视频教程—布尔教育
共24课时 | 7万人学习
Python教程之开发跨平台的记事本视频教程
共12课时 | 2.6万人学习









