1

I have here a PayPal IPN script, but the problem is, it is receiving the POST request correctly, but when it tries to make a CURL request to PayPal, it seems that no response is given by PayPal (not even INVALID or anything!)

Here is my code:

<?php
    // Format POST values
    foreach($_POST as $name => $value) {
        $data .= $name.'='.$value.'&';
    }
    $data = substr_replace($data, NULL, -1);
    $data = urlencode($data);


    // THE PROBLEM COMES HERE, I TRY TO MAKE A CURL REQUEST TO PAYPAL BUT NO RESPONSE RETURNED
    $ch = curl_init('https://sandbox.ipnpb.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

    $res = curl_exec($ch);
    $res = curl_close($ch);

    file_put_contents('result.txt',$res);
    // There is nothing in my result.txt file for $res , but $data returns the POST data PayPal gave me
?>
1
  • You are overwriting $res with the output of curl_close, which returns nothing, so result.txt will always be empty.
    – Anony Mous
    Nov 2, 2022 at 18:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.