【问题标题】:PHP PayPal header location doesn't workPHP PayPal标头位置不起作用
【发布时间】:2016-01-19 18:42:03
【问题描述】:

我有这个 PHP 代码开始购买 PayPal 沙盒:

$querystring = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$querystring .= "?business=" . urlencode($_PayPalApiUsername) . "&";
$querystring .= "item_name=" . urlencode($premium_item["name"]) . "&";
$querystring .= "item_number=" . urlencode($premium_item["number"]) . "&";
$querystring .= "amount=" . urlencode($premium_item["price"]) . "&";
$querystring .= "currency_code=" . urlencode($_PayPalCurrencyCode) . "&";

$querystring .= "cmd=" . urlencode($_POST["cmd"]) . "&";
$querystring .= "payment_key=" . urlencode(generateRandomString(16)) . "&";

$querystring .= "return=" . urlencode(stripslashes($_PayPalReturnURL)) . "&";
$querystring .= "cancel_return=" . urlencode(stripslashes($_PayPalCancelURL)) . "&";
$querystring .= "notify_url=" . urlencode($_PayPalNotifyURL);

header('location:' . $querystring);
exit();

最后$querystring 包含:https://www.sandbox.paypal.com/cgi-bin/webscr?business=business%40email.de&item_name=Starter-Kit&item_number=1000&amount=2.99&currency_code=EUR&cmd=_xclick&payment_key=7qm5en3B253FPxnu&return=http%3A%2F%2Fexample.com%2Fgame%2Fpremium.php%3Ftask%3Dsuccess&cancel_return=http%3A%2F%2Fexample.com%2Fgame%2Fpremium.php%3Ftask%3Dcancel&notify_url=http%3A%2F%2Fexample.com%2Faction%2Fnotify_payment_paypal.php(地址已更改)。

如果我手动将此链接插入浏览器地址行,我将被重定向到 PayPal 结帐页面。所以链接应该是正确的。

但是如果我使用header location(如代码所示),我将被重定向到 PayPal Sandbox 的主页(https://www.sandbox.paypal.com/home)。

有人知道怎么回事吗?

【问题讨论】:

  • 跟踪发出的 HTTP 请求(Chrome、Firefox 中的常用功能)。然后,您可以看到直接浏览 $querystring 与让您的网站将您重定向到它之间到底有什么区别。
  • 感谢@Maximilian Gerhardt,看来header location 无法解析&。我用& 替换了它们,它可以工作。不确定这是否是最佳解决方案。

标签: php paypal


【解决方案1】:

您必须将数据发布到 Payments Standard。您正试图将它们全部放入查询字符串 (GET)

看到这个example from PayPal

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="herschelgomez@xyzzyu.com">

<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">

<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Hot Sauce-12oz Bottle">
<input type="hidden" name="amount" value="5.95">
<input type="hidden" name="currency_code" value="USD">

<!-- Display the payment button. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >

</form>

【讨论】:

  • 但是如果我手动调用链接它的 GET ,不是吗?我看到许多使用此代码的教程。他们工作。
  • 有一个可以链接的使用 GET 的示例吗?
  • 我遵循这个教程:Tutorial
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 2013-07-28
  • 2011-04-02
相关资源
最近更新 更多