简体   繁体   English

无法从 Drupal 重定向到 PayPal

[英]Unable to redirect from Drupal to PayPal

I'm totally new to Drupal.我对 Drupal 完全陌生。 I created a form in Drupal using pure HTML when the user clicks on pay I call a PHP file just to get some database information subsequently this PHP redirects to another PHP that puts the PayPal payment together.当用户点击支付时,我使用纯 HTML 在 Drupal 中创建了一个表单,我调用一个 PHP 文件只是为了获取一些数据库信息,随后这个 PHP 重定向到另一个将 PayPal 付款放在一起的 PHP。

For some reason the PayPal payment PHP does not redirect to PayPal when it is called from under Drupal.出于某种原因,当从 Drupal 下调用 PayPal 付款 PHP 时,它不会重定向到 PayPal。 My layers are as follows:我的图层如下:

https://example.com/test/?q=node/11 --> call savedatatoDB.php --> call paypalpreparepayment.php --> redirect to paypal https://example.com/test/?q=node/11 --> 调用 savedatatoDB.php --> 调用 paypalpreparepayment.php --> 重定向到 paypal

If I call the PayPal payment PHP from the browser directly like this: https://example.com/test/paypal/restapi/sample/payments/PaymentPP.php?samount=0.005&sprice=123.45&description=products&sqty=100如果我像这样直接从浏览器调用 PayPal 支付 PHP: https : //example.com/test/paypal/restapi/sample/payments/PaymentPP.php?samount=0.005&sprice=123.45&description=products&sqty=100

it works!有用! I thought the problem could be an output before header() but it is not the case.我认为问题可能是 header() 之前的输出,但事实并非如此。

I wrote a line to write to a log file right before the redirect like this:我在重定向之前写了一行写入日志文件,如下所示:

$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$log = "{$today} ready to redirect {$sale_description}, {$sale_amount}, {$sale_quantity}, {$sale_price}\n";
//Save string to log, use FILE_APPEND to append.
file_put_contents('./log_'.date("j.n.Y").'.txt', $log, FILE_APPEND);
header("Location: $redirectUrl");
exit;

And the log shows that I'm getting that far but no redirect!日志显示我已经走了那么远但没有重定向! but again if I call that PHP directly from the browser then I see PayPal asking me to authorize.但同样,如果我直接从浏览器调用该 PHP,那么我会看到 PayPal 要求我授权。

So when I'm under Drupal UI, I'm wondering if Drupal could be blocking the redirect somehow.所以当我在 Drupal UI 下时,我想知道 Drupal 是否会以某种方式阻止重定向。

I got an answer from Drupal.org which makes sense.我从 Drupal.org 得到了一个有道理的答案。

here is the link: https://www.drupal.org/node/2365503#comment-9295613这是链接: https : //www.drupal.org/node/2365503#comment-9295613

Jaypan commented about 11 hours ago Jaypan发表于大约 11 小时前

The problem is that your redirect is on the server side, but you are triggering it with JavaScript.问题是你的重定向是在服务器端,但你是用 JavaScript 触发的。 If the trigger is in your JS, then the redirect also needs to happen in the JS.如果触发器在您的 JS 中,那么重定向也需要在 JS 中发生。 If the trigger is non-JS (submits to the server), then your redirect can be on the server side.如果触发器是非 JS(提交到服务器),那么您的重定向可以在服务器端。

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

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