Tag: ipn

SSL Connection Reset By Peer in PayPal IPN

It looks like some time ago, Paypal made some changes to its Instant Payment Notification System (IPN). With IPN Paypal notifies shop systems about successful payments. In the documentation, you will find an example script, how this works.

The only problem with this script is, it doesn’t work right now. You will find the reason in the headers, you send to Paypal. The example script states:

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

If you just use this headers, Paypal will reset the connection and the error message you get is SSL Connection Reset By Peer.

What to do? You have to extend the headers and tell Paypal explicitly to close the connection and which host you want to reach:

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

If you are using the sandbox, you have to use www.sandbox.paypal.com as host.

With this script IPN runs again and gives you your desired feedback.