> This snippet may help you. I used this to call some cc processing
> scripts from PHP. The output of the script is sent back to the
> browser untouched. It deals with sending cookies to and from the
> browser and will handle PHP style array parameters.
<snip>
What John posted is pretty much what cURL was made to do. After converting
your $HTTP_POST_DATA into a query-string-type variable ($data, in this
case), you'd have something instead like:
$ch = curl_init('http://www.somemachine.com/cgi-bin/someprogram');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $data );
curl_setopt($ch, CURLOPT_PROGRESS, 0 );
curl_setopt($ch, CURLOPT_HEADER, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Alternatively, leave $HTTP_POST_DATA unchanged, and use the Net_Curl PEAR
class:
$curl = new Net_Curl('http://www.somemachine.com/cgi-bin/someprogram');
$curl->type = 'post';
$curl->fields = $HTTP_POST_DATA;
$curl->return_transfer = 1;
$curl->header = 0;
$curl->progress = 0;
$curl->follow_location = 1;
$result = $curl->execute();
$curl->close();
if (PEAR::isError($result)) {
die($result->getMessage());
}
echo $result;
If you do use cURL, upgrade to the latest version of it (7.8) and the latest
of PHP (4.0.6). Earlier combinations leaked memory badly ... so does this
one, but only a bit, and a patch is coming Real Soon Now (tm). :)
- Colin
- Colin