1

该代码一直有效,直到检查编号 3,然后当我将它们导入数据库时​​,我得到一个空白行或有时什么也没有。当我使用

if ($_SERVER['REQUEST_METHOD'] != "POST") die ("No Post Variables");

顶部的代码,我得到“无后变量”,但我可以使用后变量来检查是否有问题。我看到从 ipn 返回的 item 变量,因为我可以使用它们,但是当我将它们导入数据库时​​,它们不会出现。

为什么我不能将它们添加到数据库中?

我已经在这个 IPN 上工作了一周,但没有结果。

    if ($_SERVER['REQUEST_METHOD'] != "POST") die ("No Post Variables"); 


    $req = 'cmd=_notify-validate';

    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }

    $url = "https://sandbox.paypal.com/cgi-bin/webscr";
    //$url = "https://www.paypal.com/cgi-bin/webscr";
    $curl_result=$curl_err='';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    curl_setopt($ch, CURLOPT_HTTPHEADER array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
    curl_setopt($ch, CURLOPT_HEADER , 0);   
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    $curl_result = @curl_exec($ch);
    $curl_err = curl_error($ch);
    curl_close($ch);

    $req = str_replace("&", "\n", $req); 



    // Check Number 1 ------------------------------------------------------------------------------------------------------------
    $receiver_email = $_POST['receiver_email'];
    if ($receiver_email != "samuel_1347268213_biz@hotmail.com") {
        $message = "Investigate why and how receiver email is wrong. Email = " . $_POST['receiver_email'] . "\n\n\n$req";
        mail("@hotmail.com", "Receiver Email is incorrect", $message, "From: samuel_1347268213_biz@hotmail.com" );
        exit(); // exit script
    }
    // Check number 2 ------------------------------------------------------------------------------------------------------------
    if ($_POST['payment_status'] != "Completed") {
        // Handle how you think you should if a payment is not complete yet, a few scenarios can cause a transaction to be incomplete
        mail("@hotmail.com", "payment_status", $message, "From: samuel_1347268213_biz@hotmail.com" );
    }

    // Connect to database ------------------------------------------------------------------------------------------------------
    require_once 'connect_to_mysql.php';

    // Check number 3 ------------------------------------------------------------------------------------------------------------
    $payer_email = $_POST['payer_email'];
    $sql = mysql_query("SELECT * FROM transactions WHERE payer_email= '".$payer_email."' LIMIT 1");
    $numRows = mysql_num_rows($sql);
    if ($numRows > 0) {
        $message = "Duplicate transaction ID occured so we killed the IPN script. \n\n\n$req";
        mail("@hotmail.com", "Duplicate txn_id in the IPN system", $message, "From: samuel_1347268213_biz@hotmail.com" );
        exit(); // exit script



$txn = $_POST['txn_id'];

$payer = $_POST['payer_email'];



$l = "INSERT INTO  transactions (txn_id,payer_email)VALUES ('".$txd ."','".$payer ."')";

mysql_query($l)or die;


// Mail yourself the details
$req .= "\n\nDataverified from Paypal!";
mail("@hotmail.com", "NORMAL IPN+++ RESULT", $req, "From: samuel_1347268213_biz@hotmail.com");
4

0 回答 0