php使用curl模拟登录discuz以及模拟发帖

http://www.361way.com/curl-zhuaqu/1482.html

<?php
discuzurl=http://127.0.0.1/discuz/;//login_url = discuzurl.logging.php?action=login;//post_fields = array();
//以下两项不需要修改
postfields[loginfield]=username;post_fields['loginsubmit'] = 'true';
//用户名和密码,必须填写
postfields[username]=tianxin;post_fields['password'] = '111111';
//安全提问
postfields[questionid]=0;post_fields['answer'] = '';
//@todo验证码
postfields[seccodeverify]=;//FORMHASHch = curl_init(loginurl);curlsetopt(ch, CURLOPT_HEADER, 0);
curl_setopt(ch,CURLOPTRETURNTRANSFER,1);contents = curl_exec(ch);curlclose(ch);
preg_match('//i', contents,matches);
if(!empty(matches))$formhash=$matches[1];elsedie(Notfoundtheforumhash.);//POSTCOOKIE,cookietempcookie_file = tempnam('./temp','cookie');
ch=curlinit(login_url);
curl_setopt(ch,CURLOPTHEADER,0);curlsetopt(ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(ch,CURLOPTPOST,1);curlsetopt(ch, CURLOPT_POSTFIELDS, postfields);curlsetopt(ch, CURLOPT_COOKIEJAR, cookiefile);curlexec(ch);
curl_close(ch);//cookiecookie,fidIDsend_url = discuz_url."post.php?action=newthread&fid=2";ch = curl_init(sendurl);curlsetopt(ch, CURLOPT_HEADER, 0);
curl_setopt(ch,CURLOPTRETURNTRANSFER,1);curlsetopt(ch, CURLOPT_COOKIEFILE, cookiefile);contents = curl_exec(ch);curlclose(ch);
//这里的hash码和登陆窗口的hash码的正则不太一样,这里的hidden多了一个id属性
preg_match('//i', contents,matches);
if(!empty(matches))$formhash=$matches[1];elsedie(Notfoundtheforumhash.);post_data = array();
//帖子标题
postdata[subject]=test2;//post_data['message'] = 'test2';
postdata[topicsubmit]="yes";post_data['extra'] = '';
//帖子标签
postdata[tags]=test;//hashhashdiscuzpost_data['formhash']=formhash;ch = curl_init(sendurl);curlsetopt(ch, CURLOPT_REFERER, sendurl);//REFERERcurlsetopt(ch, CURLOPT_HEADER, 0);
curl_setopt(ch,CURLOPTRETURNTRANSFER,0);curlsetopt(ch, CURLOPT_COOKIEFILE, cookiefile);curlsetopt(ch, CURLOPT_POST, 1);
curl_setopt(ch,CURLOPTPOSTFIELDS,post_data);
contents=curlexec(ch);
curl_close(ch);//cookieunlink(cookie_file);
?>

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(511) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
posted @   张同光  阅读(162)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示