0

Hello StackOverflow Community! I've been working on my PayPal IPN Script for quite a while, but without much success. This script is supposed to return VALID and put it in stats.txt, but for some reason this is not happening, and instead it is not working at all. I've used PayPal sandbox and the foreach POST seems to be working fine. I've tried putting the raw URL into my browser, with all the GET values, but for some reason paypal just gives me a timeout error, and doens't even return a INVALID. Here is my code:

// Get POST data and refine the GET value.
foreach ($_POST as $name => $value) {
    $postdata = $name.'='.$value.'&';
    $result .= substr('?'.$postdata, 0, -1);
}
// Verify that payment was really made.
    $verify = file_get_contents('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr/'.$result.'');

if ($verify == "VERIFIED") {
    // Any code run here will only be run if payment is verified.
    echo 'Payment success!';
    $data = "Payment made successfully.";
    $fp = fopen('stats.txt', 'a');
    fwrite($fp, $data);
    }

    elseif ($verify == "INVALID") {
    echo 'Payment Declined.';
    $data = "The payment isn't valid.";
    $fp = fopen('stats.txt', 'a');
    fwrite($fp, $data);
}

else {
    echo 'An unexpected error occured.';
    $data = "A timeout error occured.";
    $fp = fopen('stats.txt', 'a');
    fwrite($fp, $data);
}

// Let PayPal know that the IPN was successful.
header("HTTP/1.1 200 OK");

After payment, in stats.txt, the text I'm getting is: A timeout error occured. By the way, the bit at the top, what it's doing is its getting the POST data then formatting it into a GET url (eg: ?value1=text1&value2=text2)

Thanks for your help!

  • I'm pretty sure that `file_get_contents` is not what you want since it does not send any request headers on it's own. I would suggest using CURL, but if you really want to use `file_get_contents` , [this may help](https://stackoverflow.com/questions/2107759/php-file-get-contents-and-setting-request-headers) – Jamie_D Nov 21 '18 at 14:44
  • Thanks for the help, I'll give it a go, and I'll let you know if it works :) – Mark Adewale Nov 23 '18 at 09:37

0 Answers0