简体   繁体   English

PHP PayPal标头位置不起作用

[英]PHP PayPal header location doesn't work

i have this PHP code to start a PayPal Sandbox purchase: 我有以下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();

At the end $querystring contains: 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 (addresses changed). 最后$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 : $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 $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 (地址已更改)。

If i insert this link manually into the browsers address line, i will be redirected to the PayPal checkout page. 如果我将此链接手动插入浏览器地址栏中,我将被重定向到PayPal结帐页面。 So the link should be correct. 因此,链接应该是正确的。

BUT if i use header location (as seen in the code), i will be redirected to the homepage of PayPal Sandbox ( https://www.sandbox.paypal.com/home ). 但是,如果我使用header location (如代码中所示),我将被重定向到PayPal沙箱的首页( https://www.sandbox.paypal.com/home )。

Does someone knows whats wrong? 有人知道怎么了吗?

You have to POST your data to Payments Standard. 您必须将数据过帐到Payments Standard。 You're trying to put them all into the query string (GET) 您正在尝试将它们全部放入查询字符串(GET)

See this 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM