0

Here is the original code I had in my PHP script:

$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

I got an email from Paypal saying that I needed to upgrade my IPN script so that it uses HTTP/1.1. So here is what I changed my code to, based on their directions:

$header .="POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .="Content-Type: application/x-www-form-urlencoded\r\n";
$header .="Host: www.paypal.com\r\n";
$header .="Connection: close\r\n";

Payments have gone through today, but the IPN is no longer updating my database and this is the only change I made to it. Any ideas on what to do?

Thanks!

PioneerMan
  • 303
  • 4
  • 12
  • Are you sure you don't still need to specify the content length? See section 4.4 of the HTTP/1.1 spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4 – bcmoney Dec 11 '12 at 21:07

1 Answers1

0

Yes. I have just done battle with this. What worked for me was to remove the connection close header, and add a trim to the response back from PP. Here are the headers:

$header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

Here is the fsockopen:

$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

and here is the trim on the response back from PP:

if (!$fp) {
// HTTP ERROR
  error_mail("Could not open socket");
//
} else {
  fputs ($fp, $header . $req);
  while (!feof($fp)) {
    $res = trim(fgets ($fp, 1024));
    }
//
// check the payment_status is Completed
// check that receiver_email is your Primary PayPal email
//
  if ((strcmp ($res, "VERIFIED") == 0) && ($payment_status == "Completed") && ($receiver_email == $valid_receiver_email)) {

That worked for me.

Nick Cole
  • 1
  • 4