NYCPHP Meetup

NYPHP.org

[nycphp-talk] Posting data to PayPal from a script using sockets

drydell at att.net drydell at att.net
Thu Jun 10 13:09:51 EDT 2004


I use POST to send xml data to a foreign UNIX server... I suggest that you include User-Agent and Connection: Close headers. The other thing, which I'm not sure is server-specific or not, is that I use \n to delimit headers, not \r\n. This code snippet has been in working in production for about 4 months: 

$header = "POST $remote_url HTTP/1.0\n";
$header .= "Host: $remote_server\n";
$header .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\n";
$header .= "Content-type: text/xml\n";
$header .= "Content-length: ".strlen($data)."\n";
$header .= "Connection: Close\n\n";

$fp = fsockopen($remote_server, 80, &$errno, &$errstr);

if ($fp) {
   fputs($fp, "$header$request");
   $response = "<br><br>Connected to $remote_server$remote_url<br><br>RESPONSE :: <br>";
   while (!feof($fp)) { $response .= fgets($fp, 128); }
   fclose($fp);
   $return = $response;
} else {
   $return = "<br><br>Cannot connect to $remote_server<br>errno::$errno<br>errstr::$errstr";
 }

return $return;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20040610/0a69066f/attachment.html>


More information about the talk mailing list