PHP curl module problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
rolanddev
Forum Newbie
Posts: 9
Joined: Mon Jul 05, 2010 12:28 pm
Location: Bucharest

PHP curl module problem.

Post 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!
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: PHP curl module problem.

Post 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);
?>
User avatar
rolanddev
Forum Newbie
Posts: 9
Joined: Mon Jul 05, 2010 12:28 pm
Location: Bucharest

Re: PHP curl module problem.

Post 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...
Post Reply