title: I am trying to integrate paypal ipn to my website. I keep receiving the following error. Im at my wits end here. What am I missing?
body: <p>I am trying to integrate paypal ipn to my website. I keep receiving the following error. Im at my wits end here. What am I missing??? I guess Im am just not understanding why the ipn.php page would not be seeing what paypal is sending to the POST variable or is this even the issue? I have been at it all day and I am new to this process so any help would be great!!</p>
  
  <pre><code>INVALID
  [2015-12-02 17:39 America/Denver] Invalid IPN: cmd=_notify-validate
  </code></pre>
  
  <p>Here is my code
  ipn.php</p>
  
  <pre><code>&lt;?php
  // CONFIG: Enable debug mode. This means we'll log requests into 'ipn.log' in the same directory.
  // Especially useful if you encounter network errors or other intermittent problems with IPN (validation).
  // Set this to 0 once you go live or don't require logging.
  define("DEBUG", 1);
  // Set to 0 once you're ready to go live
  define("USE_SANDBOX", 1);
  define("LOG_FILE", "./ipn.log");
  // Read POST data
  // reading posted data directly from $_POST causes serialization
  // issues with array data in POST. Reading raw POST data from input stream instead.
  $raw_post_data = file_get_contents('php://input');
  $raw_post_array = explode('&amp;', $raw_post_data);
  $myPost = array();
  foreach ($raw_post_array as $keyval) {
      $keyval = explode ('=', $keyval);
      if (count($keyval) == 2)
          $myPost[$keyval[0]] = urldecode($keyval[1]);
  }
  // read the post from PayPal system and add 'cmd'
  $req = 'cmd=_notify-validate';
  if(function_exists('get_magic_quotes_gpc')) {
      $get_magic_quotes_exists = true;
  }
  foreach ($myPost as $key =&gt; $value) {
      if($get_magic_quotes_exists == true &amp;&amp; get_magic_quotes_gpc() == 1) {
          $value = urlencode(stripslashes($value));
      } else {
          $value = urlencode($value);
      }
      $req .= "&amp;$key=$value";
  }
  // Post IPN data back to PayPal to validate the IPN data is genuine
  // Without this step anyone can fake IPN data
  if(USE_SANDBOX == true) {
      $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
  } else {
      $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
  }
  $ch = curl_init($paypal_url);
  if ($ch == FALSE) {
      return FALSE;
  }
  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, $req);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  if(DEBUG == true) {
      curl_setopt($ch, CURLOPT_HEADER, 1);
      curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
  }
  // CONFIG: Optional proxy configuration
  //curl_setopt($ch, CURLOPT_PROXY, $proxy);
  //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  // Set TCP timeout to 30 seconds
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
  // CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
  // of the certificate as shown below. Ensure the file is readable by the webserver.
  // This is mandatory for some environments.
  //$cert = __DIR__ . "./cacert.pem";
  //curl_setopt($ch, CURLOPT_CAINFO, $cert);
  $res = curl_exec($ch);
  if (curl_errno($ch) != 0) // cURL error
      {
      if(DEBUG == true) { 
          error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
      }
      curl_close($ch);
      exit;
  } else {
          // Log the entire HTTP response if debug is switched on.
          if(DEBUG == true) {
              error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE);
              error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);
          }
          curl_close($ch);
  }
  // Inspect IPN validation result and act accordingly
  // Split response headers and payload, a better way for strcmp
  $tokens = explode("\r\n\r\n", trim($res));
  $res = trim(end($tokens));
  if (strcmp ($res, "VERIFIED") == 0) {
      // check whether the payment_status is Completed
      // check that txn_id has not been previously processed
      // check that receiver_email is your PayPal email
      // check that payment_amount/payment_currency are correct
      // process payment and mark item as paid.
      // 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(DEBUG == true) {
          error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
      }
  } else if (strcmp ($res, "INVALID") == 0) {
      // log for manual investigation
      // Add business logic here which deals with invalid IPN messages
      if(DEBUG == true) {
          error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>orderdetails.php</p>
  
  <pre><code>&lt;?php
  require 'ipn.php';
  
  ?&gt;
  
  &lt;form target="_new" method="post" action="https://www.kathyhaggerty.info/Final/ipn.php"&gt;
  &lt;input type="hidden" name="SomePayPalVar" value="SomeValue1"/&gt;
  &lt;input type="hidden" name="SomeOtherPPVar" value="SomeValue2"/&gt;
  
  &lt;!-- code for other variables to be tested ... --&gt;
  
  &lt;input type="submit"/&gt;
  &lt;/form&gt;
  &lt;br /&gt;
  Thank you for your payment. Your transaction has been completed, and a receipt for your purchase has been emailed to you. You may log into your account at &lt;a href="http://www.sandbox.paypal.com/ie"&gt;www.sandbox.paypal.com/ie&lt;/a&gt; to view details of this transaction.
  </code></pre>
  
  <p>index.php</p>
  
  <pre><code>&lt;!-- INFO: The post URL "checkout.php" is invoked when clicked on "Pay with PayPal" button.--&gt;
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;form action='checkout.php' METHOD='POST'&gt;
      &lt;input type='image' name='paypal_submit' id='paypal_submit'  src='https://www.paypal.com/en_US/i/btn/btn_dg_pay_w_paypal.gif' border='0' align='top' alt='Pay with PayPal'/&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  
  &lt;!-- Add Digital goods in-context experience. Ensure that this script is added before the closing of html body tag --&gt;
  
  &lt;script src='https://www.paypalobjects.com/js/external/dg.js' type='text/javascript'&gt;&lt;/script&gt;
  
  
  &lt;script&gt;
  
      var dg = new PAYPAL.apps.DGFlow(
      {
          trigger: 'paypal_submit',
          expType: 'instant'
           //PayPal will decide the experience type for the buyer based on his/her 'Remember me on your computer' option.
      });
  
  &lt;/script&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>I am at a loss!!</p>