Jump to content

[SOLVED] How can I see POSTed variables to debug a background script???


vozzek

Recommended Posts

Hi everyone,

 

I've been playing with a PayPal sandbox account, and I've got an Instant Payment Notification (ipn.php) script I need some help with.  In short, this script runs in the background on PayPal's site when the payment process is completed... once finished, the user is sent back to my own site.

 

Since the php script is running on PayPal's site, I can't echo or print anything to the screen.  I've tried setting some $_SESSION variables, but for some reason that wasn't working either.

 

Below is my ipn.php script in it's entirety.  If anyone sees any obvious problems with it, please let me know.  My database is (obviously) MySQL:

 

<—php
// this page only processes a POST from paypal website
// so make sure that the one requesting this page comes
// from paypal. we can do this by checking the remote address
// the IP must begin with 66.135.197.

if (strpos($_SERVER['REMOTE_ADDR'], '66.135.197.') === false) {
exit;
}

require_once 'paypal.inc.php';

// repost the variables we get to paypal site
// for validation purpose
$result = fsockPost($paypal['url'], $_POST); 

//check the ipn result received back from paypal
if (eregi("VERIFIED", $result)) { 

        require_once('../../Connections/TFATP_paypal.php');  // This is connecting okay, I verified this through error logs
            
        // check that the invoice has not been previously processed
        $sql = "SELECT status
                FROM tbl_order
                WHERE order_id = {$_POST['invoice']}";  // I'd really like to write out the value of $_POST['invoice']... just to check it

        $result = mysql_query($sql) or die(mysql_error());  // I know I got this far, because I had a syntax error here (since fixed)
            

        // if no invoice with such number is found, exit
  if (mysql_num_rows($result) == 0) {  
            exit;  // I suspect it might be bailing out here... 
        } else {
        
            $row = mysql_fetch_assoc($result);
            // process this order only if the status is still 'new'
            if ($row['status'] !== 'new') {
                exit;
            } else {

                // check that the buyer sent the right amount of money
                $sql = "SELECT total_cost
                        FROM tbl_order
                        WHERE order_id = {$_POST['invoice']}";
                        
       $result = mysql_query($sql) or die(mysql_error());
                $row    = mysql_fetch_assoc($result);  
                
                $subTotal = $row['total_cost'];
    $total    = $subTotal;
                //$total    = $subTotal + $shopConfig['shippingCost'];
                            
                if ($_POST['payment_gross'] != $total) {
                    exit;
                } else {
                   
     $invoice = $_POST['invoice'];
     $memo    = $_POST['memo'];
     if (!get_magic_quotes_gpc()) {
      $memo = addslashes($memo);
     }
     
                    // ok, so this order looks perfectly okay
                    // now we can update the order status to 'paid'
                    // update the paypal_memo too
                    $sql = "UPDATE tbl_order
                            SET status = 'paid', paypal_memo = '$memo', last_update = NOW()
                            WHERE order_id = $invoice";
        $result = mysql_query($sql) or die(mysql_error());
                }
            }
        }

} else { 
exit;
} 
–>

 

PayPal is definitely running the script.  After debugging some syntax problems by looking through my error log, the script is no longer erroring out.  However, it's still quitting (exiting) out early, and I'm not sure exactly where.

 

Can anyone suggest how to output the variables, either to the screen or elsewhere, so I can try to debug my code?

 

Thanks in advance for the help.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.