tags:

views:

52

answers:

3

I am trying to send simple entries in a form using PHP cURL so the remote server that the entries go to receives them in exactly the same manner as if sent from the form. So far, the remote server accepts post from the form but not when sent by this PHP code. fopen and fsockopen etc. are set to off by the host (Yahoo) that I use so cURL seems the best alternative.

$URL="http://remote_server.cgi";
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.8) Gecko/20100722 Ant.com Toolbar 2.0.1 Firefox/3.6.8 ( .NET CLR 3.5.30729)   AutoPager/0.6.1.22';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $URL); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_exec ($ch);    
curl_close ($ch);

The remote server will not accept the entries when sent this way.

What can be done to make the entries be received the same as if sent by the form?

 FORM action="http://remote_server.cgi" method="POST"
A: 

You are probably missing the referer and adding the headers from the form Normally they check only these two

   $headers[]='Content-type: application/x-www-form-urlencoded';
   $referer="Form url goes here";
   curl_setopt($process, CURLOPT_HTTPHEADER, $headers); 
   curl_setopt($s,CURLOPT_REFERER, $referer); 
Hansy
+1  A: 

The best way to do this IMO, is to use an HTTP proxy to inspect the working request. Fiddler, Charles and Firebug will all do the trick. Look at all of the headers that are included in working submissions to see what you might be missing.

sberry2A
A: 

Thank you for that suggestion, Hansy.

However, it is still not accepted.

Is there anything else that it could be?

I have looked at the Firefox http plugin when sending from the form but can't determine what else it is likely to be.

Sberry2A, good suggestion.

I have not used any of those before and am trying to understand Firebug. It says, "To see the HTTP headers, just click the arrow to the left of each request to expand it."

I see lots of info but am having difficulty finding what is a "request" and its "arrow".

tableman
Then using a plugin like "live http headers" , "firebug" or something to inspect the headers being sent and replicate them (adding to $headers[] array)
Hansy
Enable firebug. Then click on Net and set to enabled. After that you should be able to see all of the requests bent made through your browser. Go to the form, fill it out and submit it. Once you do you will see the POST or GET request and can click on it to inspect both the request and response headers.
sberry2A