Re: paypal ipn not working, send to failed.php
Posted: Wed Dec 19, 2012 6:20 pm
I'm sorry I don't have time to go through all that code. I do see a couple of things.
First if I remember right the IPN verification string you're reading contains a lot of data along with the word "VERIFIED" or "INVALID". However you're using strcmp to test this long string for one substring. Strcmp returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. I don't think the $res string will just have the single word "VERIFIED" or "INVALID" but I'm going from memory, you'll want to check that.
Try using preg_match instead:
Also you should be posting back to PayPal with http 1.1 as they are stopping support for 1.0 soon. Change to HTTP/1.1 and add the host line with the paypal_url.
I might have more time to look at this further tomorrow.
First if I remember right the IPN verification string you're reading contains a lot of data along with the word "VERIFIED" or "INVALID". However you're using strcmp to test this long string for one substring. Strcmp returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. I don't think the $res string will just have the single word "VERIFIED" or "INVALID" but I'm going from memory, you'll want to check that.
Try using preg_match instead:
Code: Select all
if (preg_match("/VERIFIED/",$res) === 1) {
echo "PAYPAL VERIFIED IPN DATA!\n";
}
else echo "Invalid IPN\n";Code: Select all
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: " . $paypal_url . "\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";