Php 贝宝IPN赢得';t执行代码的某些部分

Php 贝宝IPN赢得';t执行代码的某些部分,php,paypal,paypal-sandbox,paypal-ipn,Php,Paypal,Paypal Sandbox,Paypal Ipn,我正在尝试使用PayPal IPN系统。我已经将代码设置为使用他们的沙箱平台进行测试。我正在寻找我的代码的if(strcmp($res,“VERIFIED”)==0{部分没有执行的原因。不仅如此,这段代码的任何部分都没有向“log.txt”写入任何输出 我希望能对我的代码进行检查,让我知道哪里出了问题 <?php require_once('includes/mysql.inc.php'); if($_POST) { $req = 'cmd=' . urlencode('_not

我正在尝试使用PayPal IPN系统。我已经将代码设置为使用他们的沙箱平台进行测试。我正在寻找我的代码的
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');
    }
}
?>

我修复了它!我只是添加了“if($\u POST['payment\u status']=“Completed”){”,代码现在执行为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']);
            }
        }
    }
}
?>


可能它无法写入文件?请尝试在执行此代码之前添加错误报告(E_ALL)和ini_set('display_errors',1)(如果您的代码中没有其他任何地方)。好吧,这实际上帮了我很多忙。条件现在正在运行,而不是我需要运行的条件……”if(strcmp($res,“VERIFIED”)==0){"可能是paypal的结果包含了一些额外的空格?比较失败的最明显原因是字符串不一样。不。这很奇怪。当我通过沙箱系统运行paypal IPN测试时,它工作得很好。当我从沙箱切换到paypal.com时,它不再工作了?如果我尝试这个fgets re也变成了大量的标题。我想这些都是给你带来麻烦的。另外,不确定这是否只是粘贴的代码,但你在这段代码中有一个double
else
语句,这让我的PHP崩溃了。