Paypal IPN 侦听器正在使我们的网站崩溃
Posted
技术标签:
【中文标题】Paypal IPN 侦听器正在使我们的网站崩溃【英文标题】:Paypal IPN listener is crashing our site 【发布时间】:2013-05-15 05:38:24 【问题描述】:我正在尝试设置 Paypal,以便当客户购买我们网站的订阅时,他们的帐户会获得批准。不幸的是,在测试我的 IPN 监听器时,我相信我不小心设法让 Paypal 在我们的网站上发起了拒绝服务攻击。有谁知道这可能是什么原因造成的?这是 IPN 侦听器:
// read the post from PayPal system and add 'cmd'
$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.sandbox.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp)
// HTTP ERROR
else
fputs ($fp, $header . $req);
while (!feof($fp))
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
// check the payment_status is Completed
// check that receiver_email is your Primary PayPal email
if (($payment_status == 'Completed') && ($receiver_email == $paypalemail))
// check that txn_id has not been previously processed
// check that payment_amount/payment_currency are correct
// process payment
if ($clientstatus == PENDING)
$query = "UPDATE clients SET clientStatus = 'APPROVED', substatus = '1'
WHERE clientID=$item_number";
$db2->query( $query );
else if (strcmp ($res, "INVALID") == 0)
// log for manual investigation
fclose ($fp);
?>
另外,我收到了来自我的主机的一封电子邮件,其中包含我们错误日志的最后 100 行 - 基本上是这 10 次,都在 1 秒内。
[Fri May 17 13:07:16 2013] [error] [client 173.0.82.126] php Warning:
fgets(): 2 is not a valid stream resource in /var/www/vhosts/
site.com/subdomains/development.site.com/httpdocs/hiddenadmin/ipn/index.phpon
line 33
[Fri May 17 13:07:16 2013] [error] [client 173.0.82.126] PHP Warning:
fclose(): 2 is not a valid stream resource in /var/www/vhosts/
site.com/subdomains/development.site.com/httpdocs/hiddenadmin/ipn/index.phpon
line 53
[Fri May 17 13:07:16 2013] [error] [client 173.0.82.126] PHP Warning:
feof(): 2 is not a valid stream resource in /var/www/vhosts/
site.com/subdomains/development.site.com/httpdocs/hiddenadmin/ipn/index.phpon
line 32
【问题讨论】:
【参考方案1】:PayPal 现在对 IPN 使用 HTTP 1.1。 X.com 上的示例脚本已更新以反映更改。我建议尝试使用更新的脚本之一。
您提供的代码也响应沙盒环境。如果您不使用会导致帖子验证失败的沙盒。
【讨论】:
谢谢,IPN 现在可以正常工作了。我实际上得到了基于Paypal's example scripts 的代码。他们真的需要更新,我们为此与我们的主机发生了麻烦。 好。我很高兴你能把它整理好。我会看看我能做些什么来更新这些脚本。它们不应该再被使用了。以上是关于Paypal IPN 侦听器正在使我们的网站崩溃的主要内容,如果未能解决你的问题,请参考以下文章