Jump to content

cURL post not working


tableman

Recommended Posts

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 iframe height is a problem 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 and not having to fiddle with javascript.

 

The first PHP code I try is prevented from working and I discover that the apparent cause is the issue of fopen and fsockopen etc. being set to off by the host that I use because of security concerns:

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

The host has cURL so I try that but the form entries are not being accepted as they are with a direct post from the form:

$URL="http://remote_server.cgi";
$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 is a problem at the remote server, I added:

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

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

print_r($_POST);

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

 

Apparently the post data is not being sent like the form sends it.

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/210680-curl-post-not-working/
Share on other sites

The host runs PHP version 4.3.11.  The posted fields are not themselves arrays.

 

CURLOPT_POSTFIELDS may expect $_POST to be urlencoded and in querystring format, so I added:

$postfields=array();
foreach($_POST as $key=>$val) $postfields[]="$key=".urlencode($val);
$postfields = join("&", $postfields);

However, same error message.

 

Anyone?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.