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:\r\n\r\n";

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

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

The following two tabs change content below.
Seine erste Webseite hat David Remer 1998 in HTML verfasst. Wenig später war er fasziniert von DHTML und JavaScript. Heute konzentriert sich vor allem auf das Entwickeln von WordPress Themes und Plugins für Inpsyde. Außerdem hat er das Buch "WordPress für Entwickler" verfasst.

Latest posts by David Remer (see all)