PayPal IPN使用PHP生成HTTP 302错误 [英] PayPal IPN generating a HTTP 302 error using PHP

查看:99
本文介绍了PayPal IPN使用PHP生成HTTP 302错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的IPN脚本,并且已经运行了一段时间.最近,我开始收到HTTP/1.1 302 Moved Temporarily作为响应,无法确定原因.

I have an IPN script that runs, and has worked for some time now. Recently I started getting an HTTP/1.1 302 Moved Temporarily as a response and cannot determine why.

以下是与发布到PayPal并获取响应有关的代码:

The following is the code related to posting to PayPal and getting the response:

$sd = @fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if(!$sd) {
    $error = 'Error opening socket connection to PayPal: '.$errstr;
    quit($error, $errno);
}

$req = 'cmd=_notify-validate';
foreach($_POST as $key=>$value) $req .= "&{$key}=".urlencode(stripslashes($value));

// post back to PayPal to validate
$header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($req)."\r\n";
$header .= "Host: http://www.paypal.com/\r\n";
$header .= "Connection: close\r\n\r\n";

fputs($sd, $header.$req);
$response = '';
while(!feof($sd)) $response .= fgets($sd, 4096);
fclose($sd);

注意,所有的连接,传输和响应均有效,我没有得到并报错.但是PayPal的回应是不正确的,因为它没有提供其文档中所述的VERIFIED或INVALID,而是HTTP 302错误.

Note, all the connection, transfer, and responses work, I do not get and error. But the response from PayPal is not correct in that it does not provide VERIFIED or INVALID as stated in their documentation, but rather an HTTP 302 error.

推荐答案

HTTP头中的主机必须设置为www.paypal.com.请注意缺少http[s]://.

Host, in the HTTP header, must be set to www.paypal.com. Notice the lack of http[s]://.

这篇关于PayPal IPN使用PHP生成HTTP 302错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆