2
votes

For many years my PayPal IPN script has worked. Yesterday it broke and our web server has had no changes. When I receive an IPN, my PHP script calls:

    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';

    foreach ($_POST as $key => $value)
    {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }

    // post back to PayPal system to validate
    $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";
    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 120);
    if ($fp)
    {
        fputs ($fp, $header . $req);
        while (!feof($fp))
        {
          ...
        }
    }
}

PayPal's docs now talk about:

Send response messages back to PayPal:

https://ipnpb.sandbox.paypal.com/cgi-bin/webscr (for Sandbox IPNs)

https://ipnpb.paypal.com/cgi-bin/webscr (for live IPNs)

Is my above code no longer supported? PayPal is calling me but it seems not to be validating.

1

1 Answers

4
votes

This is an HTTP/1.1 issue.

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

...

if (strcmp(trim($result), "VERIFIED") == 0)