Php PayPal IPN未插入数据库

Php PayPal IPN未插入数据库,php,mysql,paypal,paypal-ipn,Php,Mysql,Paypal,Paypal Ipn,我在localhost上测试了paypal捐赠按钮,它第一次将支付金额插入mysql数据库(在phpmyadmin上验证)。但在那之后它就停止工作了 下面有什么东西会阻止它工作吗 config.php <?php require "paypal_integration_class/paypal.class.php"; require "config.php"; require "connect.php"; $p = new paypal_class; $p->paypal_url

我在localhost上测试了paypal捐赠按钮,它第一次将支付金额插入mysql数据库(在phpmyadmin上验证)。但在那之后它就停止工作了

下面有什么东西会阻止它工作吗

config.php

<?php

require "paypal_integration_class/paypal.class.php";
require "config.php";
require "connect.php";

$p = new paypal_class;
$p->paypal_url = $payPalURL;

if ($p->validate_ipn()) {
    if($p->ipn_data['payment_status']=='Completed')
    {
        $amount = $p->ipn_data['mc_gross'] - $p->ipn_data['mc_fee'];

        mysql_query("   INSERT INTO dc_donations (transaction_id,donor_email,amount,original_request)
                        VALUES (
                            '".esc($p->ipn_data['txn_id'])."',
                            '".esc($p->ipn_data['payer_email'])."',
                            ".(float)$amount.",
                            '".esc(http_build_query($_POST))."'
                        )");
    }
}

function esc($str)
{
    global $link;
    return mysql_real_escape_string($str,$link);
}
?>

我注意到的第一件事是,只有在付款状态为“已完成”时,才运行DB更新。您的付款可能正在等待,在这些情况下,代码当然会被跳过

你到底是如何在当地进行测试的?您是否使用了IPN模拟器,或者您是否运行了一个实际的沙箱事务,以便系统像真正的订单一样触发?处理PHP后,notify_url的实际值是多少?您使用的是$url,但它的价值是什么?如果它是“localhost”,它将无法工作


您是否检查了PayPal IPN历史记录,以查看它是否显示IPN正在被发送,并且可能会得到错误结果?您是否检查了web服务器日志以查看该脚本是否受到攻击?

我通过向一个沙箱帐户付款来测试它(我认为这是原因,因为IPN状态都是“重试”。$url是
$url='http://'。$\u server['server\u NAME'].dirname($\u server['REQUEST\u URI'])
这是localhost。它在第一次将详细信息插入数据库中,因此我认为localhost不是问题。如果IPN历史记录中的状态正在重试,这意味着它得到了错误的响应。如果您的实际值是localhost,那么从PayPal来时就没有办法了。对于PayPal的服务器,localhosts本身就是,所以你让他们向自己发送IPN,这当然不是你想要做的。他们可能只是得到404结果,因为他们的服务器上没有你拥有的相同文件。你必须对第一个有效的IPN进行其他操作,因为如果他们访问本地主机,它不可能来自PayPal。
<!-- The PayPal Donation Button -->



<form action="<?php echo $payPalURL?>" method="post" class="payPalForm">
<div>
    <input type="hidden" name="cmd" value="_donations" />
    <input type="hidden" name="item_name" value="Donation" />

    <!-- Your PayPal email: -->
    <input type="hidden" name="business" value="<?php echo $myPayPalEmail?>" />

    <!-- PayPal will send an IPN notification to this URL: -->
    <input type="hidden" name="notify_url" value="<?php echo $url.'/ipn.php'?>" /> 

    <!-- The return page to which the user is navigated after the donations is complete: -->
    <input type="hidden" name="return" value="<?php echo $url.'/thankyou.php'?>" /> 

    <!-- Signifies that the transaction data will be passed to the return page by POST -->
    <input type="hidden" name="rm" value="2" /> 


    <!--    General configuration variables for the paypal landing page. Consult 
            http://www.paypal.com/IntegrationCenter/ic_std-variable-ref-donate.html for more info  -->

    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="cbt" value="Go Back To The Site" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="lc" value="US" />
    <input type="hidden" name="currency_code" value="USD" />




    <input type="double" name="amount">

    <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest" />

    <!-- You can change the image of the button: -->
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!" />

  <img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</div>
</form>