PHP PayPal标头位置不起作用

时间:2016-01-19 18:42:03

标签: php paypal

我有这个PHP代码来开始购买PayPal Sandbox:

$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)的主页。

有人知道什么是错的吗?

1 个答案:

答案 0 :(得分:0)

您必须将数据发布到付款标准。您正试图将它们全部放入查询字符串(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>