php curl 发布到 PHPBB
Posted
技术标签:
【中文标题】php curl 发布到 PHPBB【英文标题】:php Curl posting to PHPBB 【发布时间】:2013-01-14 21:19:38 【问题描述】:我曾经通过我的帐户通过 php 脚本向论坛发布更新,最近它停止工作了,我不能 100% 确定原因 - curl 没有返回任何错误,一切似乎除了出现的消息之外都可以。
我发布到的董事会已为我的用户设置了禁用泛洪限制,我有权发布所需的任何类型的主题
发布即时消息的代码如下(前段时间在网上找到的 - 稍作修改)
$url = "http://url.co.uk/board/"; $post_fields = 'username=user&password=pass&redirect=&login=Log+in'; $lurl = $url."ucp.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$lurl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt"); $result= curl_exec ($ch); curl_close ($ch); $sid1 = explode("sid=",$result); $sid2 = explode('&',$sid1[1]); $sid = rtrim(substr($sid2[0], 0, -29),'"'); $purl = url&"posting.php?mode=post&f=20&sid=$sid"; var_dump($purl); $ch1 = curl_init(); curl_setopt($ch1, CURLOPT_URL,$purl); curl_setopt($ch1,CURLOPT_RETURNTRANSFER,1); curl_setopt ($ch1, CURLOPT_HEADER, false ); curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch1,CURLOPT_COOKIEFILE,"cookie.txt"); $result1= curl_exec ($ch1); curl_close ($ch1); preg_match('%name="form_token" value="(.*)"\ /\>%',$result1,$security123); preg_match('%name="lastclick" value="(.*)"\ /\>%',$result1,$lastclick); preg_match('%name="creation_time" value="(.*)"\ /\>%',$result1,$ctime1); $lclick = explode('" />',$lastclick[1]); $title = "标题"; $subject = "待发帖"; $post_fields = 数组( '主题' => $标题, '消息' => htmlspecialchars_decode($subject), '图标' => 0, 'poll_title' => "投票名称", 'poll_option_text' => "投票 1\r\n投票 2", 'poll_max_options' => 1, 'poll_length' => 0, 'poll_vote_change' => "开", 'disable_smilies' => 0, 'attach_sig' => 1, '通知' => 0, 'topic_type' => 2, 'topic_time_limit' => "", 'creation_time' => $ctime1[1], 'lastclick' => $lclick[0], 'form_token' => $security123[1], 'sid' => $sid, '发布' => '提交', ); print_r($post_fields); $ch1 = curl_init(); curl_setopt($ch1, CURLOPT_URL,$purl); curl_setopt($ch1, CURLOPT_POST, 1); curl_setopt($ch1, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch1,CURLOPT_RETURNTRANSFER,1); curl_setopt ($ch1, CURLOPT_HEADER, false ); curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch1,CURLOPT_COOKIEFILE,"cookie.txt"); $result2= curl_exec ($ch1); 如果(curl_errno($ch1)) echo '卷曲错误:' . curl_error($ch1); curl_close ($ch1); 回声 $result2;从这个$result2
有论坛的输出线程,但是提交的消息没有发布。
我在 $result2 中登录正常,没有显示任何错误消息。
有什么建议吗?我检查了 sid、form_token、lclick 和 creation_time,它们似乎都是相同且正确的。
卷曲详细输出
* About to connect() to site.co.uk port 80
* Trying 78.xxx.yyy.zzz... * connected
* Connected to site.co.uk (78.xxx.yyy.zzz) port 80
> POST /board/posting.php?mode=post&f=20 HTTP/1.1
Host: site.co.uk
Accept: */*
Cookie: phpbb3_9g61k_sid=693813912f38db33091212ee14102026; phpbb3_9g61k_k=; phpbb3_9g61k_u=57
Content-Length: 1914
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------2fb596b13df0
< HTTP/1.1 100 Continue
< HTTP/1.1 302 Found
< Date: Wed, 30 Jan 2013 23:21:39 GMT
< Server: Apache/2.2.22 (CentOS)
< Location: http://site.co.uk/board/viewforum.php?f=20
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
* Connection #0 to host site.co.uk left intact
* Issue another request to this URL: 'http://site.co.uk/board/viewforum.php?f=20'
* Disables POST, goes with GET
* Re-using existing connection! (#0) with host site.co.uk
* Connected to site.co.uk (78.xxx.yyy.zzz) port 80
> GET /board/viewforum.php?f=20 HTTP/1.1
Host: site.co.uk
Accept: */*
Cookie: phpbb3_9g61k_sid=693813912f38db33091212ee14102026; phpbb3_9g61k_k=; phpbb3_9g61k_u=57
< HTTP/1.1 200 OK
< Date: Wed, 30 Jan 2013 23:21:39 GMT
< Server: Apache/2.2.22 (CentOS)
< Cache-Control: private, no-cache="set-cookie"
< Expires: 0
< Pragma: no-cache
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
* Connection #0 to host site.co.uk left intact
* Closing connection #0
【问题讨论】:
是您的论坛还是其他人的论坛?也许他们阻止了你。 没有被屏蔽,我在论坛上有管理员权限,但没有文件权限。任何日志中都没有显示任何内容,当脚本运行时我可以看到我的用户名在线显示 如果您是本论坛的管理员,为什么不直接将其插入数据库,而是使用 curl? @QuyNguyen 数据库结构非常复杂。在 PhpBB3.x 数据库中手动插入帖子非常困难 不仅如此。但是缓存失效是通过代码发生的 【参考方案1】:解决了
posting.php 第 49 行
if ($cancel || ($current_time - $lastclick < 2 && $submit))
虽然对我的用户禁用了洪水,但我仍然必须坚持 2 秒的硬编码延迟。
【讨论】:
这听起来像是 PhpBB 中的错误!到 bugtracker 你应该去 该文件并非设计为 API 端点(您会看到 OP 问题 hacking the CSRF token from the page)。这是一个通过快速连续点击两次按钮来防止重复发布的功能。以上是关于php curl 发布到 PHPBB的主要内容,如果未能解决你的问题,请参考以下文章
php RAW Curl使用PHP发布到AWS Kinesis