php Curl发布到PHPBB

php Curl posting to PHPBB

我以前通过一个php脚本通过我的帐户向一个论坛发布更新,最近它已经停止工作了,我不能百分之百确定为什么-curl没有返回错误,除了出现消息之外一切似乎都正常。

我发布到的板为我的用户设置了禁用洪水限制,我有权发布任何类型的主题。

发布即时消息使用的代码如下(不久前在网上找到-小编辑)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$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 ="title";
$subject ="subject to post";
$post_fields = array(
            'subject'   => $title,
         'message'   => htmlspecialchars_decode($subject),
            'icon'      => 0,
'poll_title' =>"Poll Name",
'poll_option_text' =>"poll 1

poll 2"
,
'poll_max_options' => 1,
'poll_length' => 0,
'poll_vote_change' =>"on",


            'disable_smilies'   => 0,
            'attach_sig'        => 1,
            'notify'           => 0,
         'topic_type'         => 2,
            'topic_time_limit'   =>"",
           'creation_time'      => $ctime1[1],
         'lastclick'          => $lclick[0],
          'form_token'   => $security123[1],
              'sid'     =>  $sid,
         'post'   => 'Submit',

         );
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);
if(curl_errno($ch1))
{
    echo 'Curl error: ' . curl_error($ch1);
}
curl_close ($ch1);
echo $result2;

从这个$result2有来自论坛的输出线程,但是提交的消息没有被发布。

我以$result2登录,没有显示错误消息。

有什么建议吗?我检查了sid,form_token,lclick和creation_time,它们看起来都是相同和正确的。

curl详细输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
* 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


解决了它

Posting.php第49行

1
if ($cancel || ($current_time - $lastclick < 2 && $submit))

虽然Flood对我的用户是禁用的,但是仍然有一个硬编码的延迟,我必须坚持2秒。