i am trying to integrate paypal IPN in my page. i use http://eliteweaver.co.uk/testing/ipntest.php to test my script. I get this error: IPN Received: Your script did not reply!
The script i am using is the paypal php code posted on their page.
<?
// 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";
}
echo"req: $req <br>";
// 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.eliteweaver.co.uk/testing/ipntest.php", 80, $errno, $errstr, 30);
echo" header: $header<br>
fp: $fp <br>";
// assign posted variables to local variables
$item_name = $POST['item_name'];
$item_number = $POST['item_number'];
$payment_status = $POST['payment_status'];
$payment_amount = $POST['mc_gross'];
$payment_currency = $POST['mc_currency'];
$txn_id = $POST['txn_id'];
$receiver_email = $POST['receiver_email'];
$payer_email = $POST['payer_email'];
if (!$fp) {
// HTTP ERROR
echo"in !\$fp <br>";
} else {
echo"in else !\$fp <br>";
fputs ($fp, $header . $req);
while (!feof($fp)) {
echo"in while !\$fp <br>";
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {echo"in verified<br>";
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {echo"in notverified<br>";
// log for manual investigation
}
}
fclose ($fp);
}
?>
i am trying to echo as much as possible to find my error... what i get returned from the echos is:
req: cmd=_notify-validate&receiver_email=...and-all-the-other-values
header: POST /cgi-bin/webscr HTTP/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 830
fp:
in !$fp
so for some reason the $fp is emtpy is that normal? therefore the code ends up in the "if (!$fp) {// HTTP ERROR }" part.
I have really no idea what my mistake is! please help! :-((
thanks
ili