PayPal IPN不会更新数据库

时间:2013-05-01 06:30:48

标签: php paypal paypal-ipn

所以出于某种原因,这个脚本不会用我在“ if(strcmp($ res,”VERIFIED“)== 0){中告诉它的内容更新我的MySQL数据库“块。然而,file_put_contents('log.txt','verif');就在那个街区,工作得很好。

<?php
    error_reporting(E_ALL);
    ini_set('display_errors',1);

    if($_POST) {
        $req = 'cmd=_notify-validate';

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

        // post back to PayPal system to validate
        $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
        $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
        $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);

        if (!$fp) {
            file_put_contents('log.txt', 'httperrrrr');
            die();
        } else {
            file_put_contents('log.txt', 'die here');
            fputs ($fp, $header . $req);
            while (!feof($fp)) {
                $res = fgets ($fp, 1024);
                if (stripos($res, "VERIFIED") !== false)
                    if ($_POST['payment_status'] = "Completed") {
                        $con = mysqli_connect("****","****","****","****");
                        // Check connection
                        if (mysqli_connect_errno()) {
                            echo "Failed to connect to MySQL: " . mysqli_connect_error();
                        }

                        $username = $_POST['custom'];
                        $date = date('Y-m-d');

                        mysqli_query($con, "UPDATE users SET access='user', invoice_paid='$date' WHERE username='$username'");
                        mysqli_close($con);
                        file_put_contents('log.txt', 'verified');
                    }
                } else if (stripos($res, "INVALID") !== false)
                    file_put_contents('log.txt', $_POST['payment_status']);
                }
            }
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

这可能不会导致您的问题,但是有一个小错误,其中检查了付款状态。您使用'='而不是'==':

if ($_POST['payment_status'] = "Completed") {