Jump to content

Getting error while posting in phpbb via curl


john_bboy7

Recommended Posts

I am getting an error when i post some thing on phpbb forum via curl i.e.

 

The submitted form was invalid. Try submitting again.

 

I even preg matched the token and added it in the posting field but still not posting.. as if i echo it.. it shows me all the text is in the right place and even the post is also submited but gives this msg aftwards.

 

========

 

And incase you guys are wondering if its a spam thing.. No its not.. that forum is mine..(i m admin) i made that forum to test my curl options.. so if there are any changes that inly admin can make .. please also let me know..as i will change them..

Link to comment
Share on other sites

  • 4 weeks later...

I got the same problem when i tried. I solved the issue.

 

it is the issue with the hidden fields. Lasttime and createdtime fields.

 

you should pass those variables in the post

 

and not only that you should post the sid and form_token values using post fields in curl.

 

it will work.

 

Below is the example code you use the code and you can start posting in the phpbb.

 

$post_fields = 'username=test&password=test&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);

// echo $result;

 

The above code is just for login into phpbb. in this you have to notice one more thing. there are two phpbb versions. In phpbb2 or before you will have login.php for logging into phpbb.

from phpbb3 it is ucp.php

when you are logging using curl you should take about it.

 

I am grabbing the sid by using the below codes.

 

$sid1 = explode("sid=",$result);

 

$sid2 = explode('&',$sid1[1]);

$sid = $sid2[0];

 

In posting to phpbb you should notice two differences again.

 

In older versions  it is mode=newthread for new versions mode=post

 

takecare of that while posting it to the forum

 

 

$purl = "http://www.geturfile.com/phpbb/posting.php?mode=post&f=2&sid=$sid";

 

$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);

// echo $result1;

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]);

 

in the above curl code i am trying to curl the posting.php to get the form_token and lastclick and the created time. using those fields i pass those in the postfields while posting a new thread

The below curl code does the actual posting to phpbb.

you can copy the code and try by yourself. There might be one or two unnecessary fields but the posting to phpbb works.

 

 

$title = "This is a title post for phpbb forum and trying to test my skills";

$subject = "This is a subject for the new topic. I hope this much of text is enough";

$post_fields = array(

            'subject'         => $title,

            'message' => nl2br(htmlspecialchars_decode($subject)),

            'icon'            => 0, 

    'disable_bbcode' => 0,

        'disable_smilies' => 0,

            'disable_magic_url' => 0,

            'attach_sig'     => 1,

            'notify'          => 0,

'topic_type'        => 0,

            'topic_time_limit'  => "",

          'creation_time'      => $ctime1[1],

        'lastclick'          => $lclick[0],

          'form_token' => $security123[1],

              'sid'    =>  $sid,

'post' => 'Submit',

 

);

 

$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_close ($ch1);

 

echo $result2;

 

// ------------------------------whole code pasting again here --------

 

$post_fields = 'username=test&password=test&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);

// echo $result;

$sid1 = explode("sid=",$result);

 

$sid2 = explode('&',$sid1[1]);

$sid = $sid2[0];

 

$purl = "http://www.geturfile.com/phpbb/posting.php?mode=post&f=2&sid=$sid";

 

$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);

// echo $result1;

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 = "This is a title post for phpbb forum and trying to test my skills";

$subject = "This is a subject for the new topic. I hope this much of text is enough";

$post_fields = array(

            'subject' => $title,

'message' => nl2br(htmlspecialchars_decode($subject)),

            'icon'      => 0,

'disable_bbcode' => 0,

  'disable_smilies' => 0,

            'disable_magic_url' => 0,

            'attach_sig'     => 1,

            'notify'          => 0,

'topic_type'        => 0,

            'topic_time_limit'  => "",

          'creation_time'      => $ctime1[1],

        'lastclick'          => $lclick[0],

          'form_token' => $security123[1],

              'sid'    =>  $sid,

'post' => 'Submit',

 

);

 

$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_close ($ch1);

 

echo $result2;

 

 

//--------------------------------------------------------------------

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.