I'm working on creating an Instant Payment Notification page to work with Paypal's payment gateway. This is from their documentation in PP_OrderManagement_IntegrationGuide.pdf:
NOTE:You can implement IPN without SSL, but PayPal recommends against doing so.
1. Your POST must be sent to https://www.paypal.com/cgi-bin/webscr.
.
.
.
AND YET....the sample code they provide at
http://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside#php
has this:
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
For anyone new to paypal work, this is pretty much typical.
QUESTIONS:
1) If I want to POST to paypal securely using fsockopen, is it possible? Can I do so by changing that to this:
$fp = fsockopen ('ssl://www.sandbox.paypal.com/cgi-bin/webscr', 43, $errno, $errstr, 30);
2) should I use cURL or something?
3) the complete lack of headers seems rather unprofessional. I saw this example in the php documentation and was considering adapting it but I'm not sure if the headers might work for this application or not. The connection:close header seems oddly placed.
<?php
$host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
# working vars
$host = 'www.example.com';
$service_uri = '/cgi-bin/processACT';
$vars ='code=22&act=TEST';
# compose HTTP request header
$header = "Host: $host\r\n";
$header .= "User-Agent: PHP Script\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($vars)."\r\n";
$header .= "Connection: close\r\n\r\n";
$fp = pfsockopen("ssl://".$host, 443, $errno, $errstr);
if (!$fp) {
echo "$errstr ($errno)<br/>\n";
echo $fp;
} else {
fputs($fp, "POST $service_uri HTTP/1.1\r\n");
fputs($fp, $header.$vars);
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>