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

    2 months later
    a month later

    hi, i'm in the process of integrating ipn with my site which caused me some confusion too.

    in a nutshell, the ipn system works by posting the transaction details to your script '/testing/ipntest.php' which in turn must re-post these details back to paypal for verification. upon receipt, paypal then replies to your post with a new set of headers stating whether the transaction is 'VERIFIED' or 'INVALID', from which your customised php code will perform some background process(es) (such as db query/insert/update statements).

    from what i can gather, i think the problem you're faced with lies within

    $fp = fsockopen ("www.eliteweaver.co.uk/testing/ipntest.php", 80, $errno, $errstr, 30);

    this line tells php to fsockopen the specified url and post the variables to the webscr script found in 'cgi-bin' for verification of the transaction (as defined by the first line of you $header string). however, the transaction details reside on paypal servers, so the url MUST point to their domain ie. www.paypal.co.uk and NOT www.eliteweaver.co.uk.

    so by changing your script to

    ...
    // 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.co.uk", 80, $errno, $errstr, 30);
    ...

    if (!$fp) should evaluate to false and the else clause should be executed.

    hope this helps. johnsworld

      Write a Reply...