<?php /* * * 作者:PHP中文网 * 类用途: 实现discuz2.5登陆发帖 */ class discuz_post{ var $login_url; var $post_login_array=array( ); var $post_url; var $cookie_file; public function get_formhash($login_url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $login_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $contents = curl_exec($ch);//print_r($contents);die; curl_close($ch); //正常发布的版本用如下方法可以获得登陆部分的formhash preg_match('/<input type="hidden"name="formhash"value="(.*)"/>/isU', $contents, $matches); //echo"<pre class="brush:php;toolbar:false">"; //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('/<input type="hidden"name="formhash"id="formhash"value="(.*)"/>/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"<pre class="brush:php;toolbar:false">"; print_r($rc); echo $theformhash; echo $the_cookie_file; echo $thesendformhash; unlink($rc->cookie_file);//删除cookie文件,也可以不删除 echo"ok!"; ?>
<?php /* * * 作者:PHP中文网 * 类用途: 实现discuz2.5登陆发帖 */ class discuz_post{ var $login_url; var $post_login_array=array( ); var $post_url; var $cookie_file; public function get_formhash($login_url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $login_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $contents = curl_exec($ch);//print_r($contents);die; curl_close($ch); //正常发布的版本用如下方法可以获得登陆部分的formhash preg_match('/<input type="hidden"name="formhash"value="(.*)"/>/isU', $contents, $matches); //echo"<pre class="brush:php;toolbar:false">"; //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('/<input type="hidden"name="formhash"id="formhash"value="(.*)"/>/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"<pre class="brush:php;toolbar:false">"; print_r($rc); echo $theformhash; echo $the_cookie_file; echo $thesendformhash; unlink($rc->cookie_file);//删除cookie文件,也可以不删除 echo"ok!"; ?>
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
2 몇 주 전ByDDD
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

Dreamweaver Mac版
시각적 웹 개발 도구
