php - 使用未定义的常量主机 - 假定 'host' Paypal 类中的错误(codeigniter 库)

标签 php codeigniter paypal paypal-sandbox paypal-ipn

我正在使用名为 paypal_class 的 codeigniter 库。一切都很好,但是在验证 ipn 函数时我得到了这个错误。 使用未定义的常量主机 - 假定为“主机”,这一定是邮件未发送给用户的原因。什么都没有返回。

我是 Paypal 新手。所以我希望有一个详细的解决方案。谢谢。请询问您可能需要的任何其他信息。


错误在这一行:

 $fp = fsockopen($url_parsed[host], "80", $err_num, $err_str, 30);

在哪里

$url_parsed = parse_url($this->paypal_url);

这是 ipn 函数:

    function validate_ipn() {

    // parse the paypal URL
    $url_parsed = parse_url($this->paypal_url);

    // generate the post string from the _POST vars aswell as load the
    // _POST vars into an arry so we can play with them from the calling
    // script.
    $post_string = '';
    foreach ($_POST as $field => $value) {
        $this->ipn_data["$field"] = $value;
        $post_string .= $field . '=' . urlencode(stripslashes($value)) . '&';
    }
    $post_string.="cmd=_notify-validate"; // append ipn command
    // open the connection to paypal
    $fp = fsockopen($url_parsed['host'], "80", $err_num, $err_str, 30);
    if (!$fp) {

        // could not open the connection.  If loggin is on, the error message
        // will be in the log.
        $this->last_error = "fsockopen error no. $errnum: $errstr";
        $this->log_ipn_results(false);
        return false;
    } else {

        // Post the data back to paypal
        fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
        fputs($fp, "Host: $url_parsed[host]\r\n");
        fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
        fputs($fp, "Content-length: " . strlen($post_string) . "\r\n");
        fputs($fp, "Connection: close\r\n\r\n");
        fputs($fp, $post_string . "\r\n\r\n");

        // loop through the response from the server and append to variable
        while (!feof($fp)) {
            $this->ipn_response .= fgets($fp, 1024);
        }
        fclose($fp); // close connection
    }

    if (preg_match("/VERIFIED/i", $this->ipn_response)) {

        // Valid IPN transaction.
        $this->log_ipn_results(true);
        return true;
    } else {

        // Invalid IPN transaction.  Check the log for details.
        $this->last_error = 'IPN Validation Failed.';
        $this->log_ipn_results(false);
        return false;
    }
}

最佳答案

你需要改变这个:

 $fp = fsockopen($url_parsed[host], "80", $err_num, $err_str, 30);

 $fp = fsockopen($url_parsed['host'], "80", $err_num, $err_str, 30);

然后在此处调试返回值:

$url_parsed = parse_url($this->paypal_url);
var_dump($url_parsed);

关于php - 使用未定义的常量主机 - 假定 'host' Paypal 类中的错误(codeigniter 库),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15803391/

相关文章:

javascript - 使用 HTML 中的外部 Javascript 文件运行 PHP 脚本

php - 由 PHP 执行的 C 应用程序在执行完成之前不会在浏览器上显示输出

ssl - Parse.Cloud.httpRequest 返回 "Request failed; 35-111 SSL connect error; Connection refused"

javascript - Paypal 智能支付抛出错误但仍在处理付款

php - 使用 codeigniter 签到/ checkout 考勤系统

html - 网站支付标准 : How would I connect the order being sent and the IPN receiving it?

php - 无法保存 12 ÷ 5 等数据

php - 获取一年中每个月的总计,包括没有结果的月份

php - 使用 codeigniter 的多图像

php - 路由到 Controller