Page 1 of 1

Post Data using PHP Curl Library

Posted: Mon Apr 28, 2008 8:10 am
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?

Re: Post Data using PHP Curl Library

Posted: Tue Apr 29, 2008 1:44 am
by louie35
anyone has any ideeas why the above code doesn't work?

Re: Post Data using PHP Curl Library

Posted: Tue Apr 29, 2008 3:48 am
by onion2k
Looks ok to me. Are you sure the problem isn't with the receiving page?

Re: Post Data using PHP Curl Library

Posted: Tue Apr 29, 2008 4:07 am
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?

Re: Post Data using PHP Curl Library

Posted: Tue Apr 29, 2008 8:56 am
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