cURL POST to remote server not accepted

Users make entries into a form on my site which are then sent to a remote server which generates a variable length page of results for the users’ perusal. I want the results to be displayed on my site but I discover that there is a problem with iframe height so I am trying PHP in a separate file to avoid an iframe. Then maybe I can cache the result pages and display them without any height difficulties. I am trying PHP first before resorting to Javascript to handle the iframe height.

The first PHP code I try generates a "… no wrapper… " error and I discover that the apparent cause is the issue of fopen and fsockopen etc. being set to “off”, because of security concerns, by the host that I use:

foreach($_POST as $key => $value)
{$url .="$key=" . urlencode($value) . "&";}
$array = file($url);]

The host runs PHP version 4.3.11 and has cURL so I try that but the form entries are not being accepted as they are with post direct from the form:

$postfields=array();        //FOR urlencode and querystring expected by CURL_POSTFIELDS 
foreach($_POST as $key=>$val) $postfields[]="$key=".urlencode($val);
$postfields = join("&", $postfields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_exec ($ch);    
curl_close ($ch);

In case useragent recognition was another security issue at the remote server causing a refusal to accept the data, I added:

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20080311 Firefox/');

I know all entries are received by the separate file by using:


But the remote server still says "Error in form found. You are not authorized… etc. etc… "

This code must not be sending the post data like the form does.

What fixes can I try?

The curl post method should handle that. You also shouldn’t need to encode if you’re passing it as an array. My only thought is that the server is looking for more headers (like maybe ContentAccept), but I’m not really sure.

Thank you, poops.

I have removed the unnecessary code.

I looked at the Firefox http plugin.

I changed the useragent to what it shows.

I also see “Content-Type: application/x-www-form-urlencoded” when sent direct from the form
Is it possible that code needs to be added to urlencode $_POST?

you can try installing the live headers plugin for firefox (
if you enable that when you post normally, you’ll see everything that’s passed (headers, post data, etc) and you can add what your missing to the curl post

hope that helps

you also don’t need these lines

$postfields=array(); //FOR urlencode and querystring expected by CURL_POSTFIELDS
foreach($_POST as $key=>$val) $postfields=“$key=”.urlencode($val);
$postfields = join(“&”, $postfields);

as you’re using the $_POST var instead of the $postfields var