I have written this but for some reason $fp returns HTTP/1.1 400 Bad Request I have no idea why this would happen. Is there something wrong? $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 ('www.paypal.com', 80, $errno, $errstr, 30); $message = $req; if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { $match = array(); $result = $req; $invoice = $_POST['invoice']; preg_match('/txn_id=([^&]*)/', $result, $transmatch); $transid = $transmatch[1]; preg_match('/mc_gross=([^&]*)/', $result, $pricematch); $price = $pricematch[1]; order_process($invoice,$transid,'Paypal'); } else if (strcmp ($res, "INVALID") == 0) { } } fclose ($fp); } PHP:
It looks fine to me. The only difference mine has is that I have an error handling function: if(!$fp) { $last_error = "fsockopen error no. $errnum: $errstr"; return false; } PHP:
That's what I thought as well, but the script I use passes only the www version and it works fine. It sounds like the server isn't allowing incomming data or something similar. Might check the firewall if there is one.
You might try testing with another service just to identify the problem. This one has worked well for me in the past. Belahost IPN Testing Environment Some scripts have problems with PayPal in test mode.
Try adding this under the POST header $header .= "Host: www.paypal.com\r\n"; PHP: Try echoing the complete header and see if it contains the expected content.
My code is good... it just doesnt work. Man I wasted my 1000th post on that. pfff I wanted to say something meaningful and wise... *think think* The crow only flies down the wicker path, yet the antellope will plunder through the grove. Think about it