Hi, Im implementing a paypal IPn script on a new website and im basically using one that i already have working for another customer on a different server. But on both sandbox test payments and also live payments i cant get a valid or invalid response. After the IPN script runs im emailing myself the $res and $req variables. Im not an expert at this but from the documentation etc the string is supposed to contain either the word VALID or INVALID. When i look through both $resand $req they are nowhere. As i say the script runs fine and reports valid on another server just not this new one. i've tried 15+ possible fixes but some report to work for some but not others...i have also tried live payments and tried re-sending the IPjn notification but am geting nowhere. Here is a simplified version of my script; // read the post from PayPal system and add 'cmd'
$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.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets($fp, 1024);
if (strcmp(trim($res), "VERIFIED") == 0) {
//update order and send emails etc
}
// if the IPN POST was 'INVALID'...do this
else if (strcmp(trim($res), "INVALID") == 0) {
// log and send email for manaul investigation
}else{ $newres=$newres.$res; }
} //email myself $newres for review
}
... View more