Post Data using PHP Curl Library

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
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post Data using PHP Curl Library

Post by louie35 »

Hi,

I am trying to post a form data using the curl library but no matter what I do it does not pass the data to the receiving page.
Here is my code:

Code: Select all

 
 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_STDERR, $curl_log); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_FAILONERROR, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0); //set to false as safe_mode = off
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_USERAGENT ,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20071204 Firefox/2.0.0.3");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($ch, CURLOPT_TIMEOUT, 200); 
$header[] = "Content-Type: text/xml"; 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
$new_result = curl_exec($ch); 
$curl_error = curl_error($ch); 
$curl_errno = curl_errno($ch); 
$curl_info = curl_getinfo($ch); 
curl_close($ch); 
echo $new_result;
 
the log file shows the data alright but the receiving page doesn't. Any ideeas why?
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Re: Post Data using PHP Curl Library

Post by louie35 »

anyone has any ideeas why the above code doesn't work?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Post Data using PHP Curl Library

Post by onion2k »

Looks ok to me. Are you sure the problem isn't with the receiving page?
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Re: Post Data using PHP Curl Library

Post by louie35 »

I tried everything but doesn't seem to be able to get the data posted. There are no redirection on the page at all so the post should be in the headers but is not.

Are there any other ways of doing this instead on Curl?
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Re: Post Data using PHP Curl Library

Post by louie35 »

Ok, I manage to get it to post the data in the end but the form I am posting to is checked using smarty and I keep getting this error at the top of the page

Code: Select all

SmartyValidate: [is_valid] form 'submit_link' is not registered
 
Post Reply