I am having problems installing PayPal IPN. It returns INVALID every time I process it. Is there something wrong with my code


    $db_host = 'localhost'; 
    $db_user = ''; 
    $db_password = ''; 
    $db_database = ''; 

    // Connect and select database
    $connect = mysql_connect($db_host, $db_user, $db_password);
    $select_db = mysql_select_db($db_database);

    // require_once('../includes/main.php');
    // Notify command
    $request = "cmd=_notify-validate";
    // Prepare the URL to send via cURL
    foreach ($_POST as $key => $value){
        if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()){  
            $value = urlencode(stripslashes($value)); 
            $value = urlencode($value); 
        $request .= "&$key=$value"; 
    // Initial cURL
    $ch = curl_init();
    // Set opt
    // Return result
    $result = curl_exec($ch);
    // Close cURL connection
    // If condition
    if($result == 'VERIFIED'){
        mysql_query("INSERT INTO paypal_ipn (verification) VALUES ('{$result}')");
        mysql_query("INSERT INTO paypal_ipn (verification) VALUES ('{$result}')");

Recommended Answers

All 3 Replies

The issue must be in the values string you set up. If you're getting 'invalid' back you can be sure you're hitting the right URL and your cURL is working but you're failing the verification.
So you're need to match your query string against the API docs and any examples to see what you're doing wrong.

As an aside you're opening database connection too early. Don't open it until the curl response comes back to minimise the time you're holding a database connection open. Probably not a big deal but a good habit to get into.

Hi hericles, Thank you. How can I match the two strings. The one from my side and the one from PayPal side? I want to see if they exactly match, or see what is the problem.

I have solved the problem. It was the payment_date that was causing the problem. It was set to: Sun May 22 2016 10:15:18 GMT+0300 (Arab Standard Time). After I changed it to: Sun May 22 2016 10:15:18 GMT It worked perfectly.

But I have another question: How can I make it work with and without payment_date?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.