Page 1 of 1

PHP curl module problem.

Posted: Mon Aug 09, 2010 5:29 am
by rolanddev
Hi. I have a very strange problem. I try to post something into a form using curl.
That website requires CURLOPT_FOLLOWLOCATION to be true because it redirects you after you posted the data.

My code is the following:

Code: Select all

    $ch = curl_init("http://pussytorrents.org/comment.php?action=add");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "text='ok'&tid=49946");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIE, 'uid=1435730; pass=d11a3799a8e1b212ba177141824ded64');
    curl_exec($ch);
    curl_close($ch);
Even though I sent the required fields: tid and text, it still gives me the message: Id is required!

Other details:
Form source code:

Code: Select all

<form method="post" action="comment.php?action=add">
<input name="tid" value="49946" type="hidden">

<textarea name="text" rows="10" cols="60"></textarea><p></p>
<p><input class="btn" value="Do it!" type="submit"></p></form>

Please help me!

Re: PHP curl module problem.

Posted: Mon Aug 09, 2010 7:09 am
by dejvos
I think the problem is in post data. I think you should use urlencode() function.

Then it will be like:

Code: Select all

<?php
 $ch = curl_init("http://pussytorrents.org/comment.php?action=add");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
   // POST vals have to be url-friendly
    curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode( "text='ok'&tid=49946"));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIE, 'uid=1435730; pass=d11a3799a8e1b212ba177141824ded64');
    curl_exec($ch);
    curl_close($ch);
?>

Re: PHP curl module problem.

Posted: Mon Aug 09, 2010 7:26 am
by rolanddev
Thanks dejvos but still doesn't work.
If you want to test it, just create a php file on localhost and run it...