Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Change this: </p> <pre><code>// post back to PayPal system to validate $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"; $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); #I also tried: $fp =fsockopen('ssl://www.paypal.com',443,$err_num,$err_str,30); </code></pre> <p>To this:</p> <pre><code>// post back to PayPal system to validate $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"; $header .= "Connection: close\r\n\r\n"; $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); </code></pre> <p>And this: </p> <pre><code>if (strcmp ($res, 'VERIFIED') == 0) { </code></pre> <p>To this: </p> <pre><code>if (strcmp (trim($res), 'VERIFIED') == 0) { </code></pre> <p>And it's pretty much guaranteed to work. </p> <p>Your current setup fails because PayPal sends a Connection: keep-alive header in the response which fsockopen gladly accepts, and thus it keeps the connection open.<br> Whereas a HTTP library such as cURL will close the connection automatically. </p> <p>My general suggestion is; if you don't want to control every single bit that goes across the line to PayPal, use a HTTP library such as cURL, rather than fsockopen which is just a plain TCP connection.<br> (PayPal has sample code using cURL available at <a href="https://www.paypal.com/ipn" rel="noreferrer">https://www.paypal.com/ipn</a> and <a href="https://www.paypal.com/pdt" rel="noreferrer">https://www.paypal.com/pdt</a>)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload