我正在尝试使用PayPal IPN系统。 我已经设置好代码以使用其SandBox平台进行测试。 我正在寻找有关if (strcmp ($res, "VERIFIED") == 0) {我的代码部分未执行的原因。 不仅如此,该代码的任何部分都没有将任何输出写入“ log.txt”。

我希望查看我的代码以使我知道我要去哪里错了。

<?php
require_once('includes/mysql.inc.php');

if($_POST) {
    $req = 'cmd=' . urlencode('_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 .= "Host: sandbox.paypal.com\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('ssl://sandbox.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);
            $data = print_r($res, TRUE);
            if (strcmp ($res, "VERIFIED") == 0) {
                file_put_contents('log.txt', 'verified');
                $username = $_POST['custom'];
                require_once('classes/admin.class.php');
                $activate = new Admin($db);
                $activate->modifyUser($username, 'activate');
            } else {
                file_put_contents('log.txt', 'noverifyshit');
            }
        }
    } else {
        file_put_contents('log.txt', 'no post');
    }
}
?>

===============>>#1 票数:0

我修好了它! 我只是添加了“ if($ _POST ['payment_status'] =“已完成”){”,代码现在执行为true。

这是我更新的代码:

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
require_once('includes/mysql.inc.php');

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 .= "Host: www.paypal.com\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 (strcmp ($res, "VERIFIED") == 0) {
                if ($_POST['payment_status'] = "Completed") {
                    file_put_contents('log.txt', 'verified');
                    $username = $_POST['custom'];
                    require_once('classes/admin.class.php');
                    $activate = new Admin($db);
                    $activate->modifyUser($username, 'activate');
                }
            } else {
                file_put_contents('log.txt', $_POST['payment_status']);
            }
        }
    }
}
?>

  ask by Jake Smith translate from so

未解决问题?本站智能推荐: