0

I have a paypal IPN listener script written in php that is causing errors, it fills up my log file very fast and crashes the server.

The error is : listener feof(): 30 is not a valid stream resource

I have hunted high and low for an up to date example of a paypal IPN listener, but it seems it is beyond paypal to provide such an example.

Here is my code:

$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}
// Post back to PayPal to validate
$server = "ssl://www.paypal.com";
$port = 443;
$timeout = 30;

$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";  // www.paypal.com for a live site
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";



$fp = fsockopen($server, $port, $errno, $errstr, $timeout);
$payment_status = $_POST['payment_status'];
$custom =  $_POST["custom"];
$txn_type = $_POST["txn_type"];

// Process validation from PayPal
if (!$fp) {

//error
echo "HTTP ERROR";

} else {

  // NO HTTP ERROR
  fputs($fp, $header . $req);

  while (!feof($fp)) {
      $res = trim(fgets ($fp, 1024));
      if (strcmp($res, "VERIFIED") == 0) {

   if ($payment_status == "Completed")
   {   
          //code to update database here
       }
      }
   }
}

Any ideas guys?

4

1 回答 1

1

Oh my GOD... This is why you have cURL!

VerifyIPN() on GitHub

PS: Buy me a drink!

于 2013-07-09T12:18:45.560 回答