使用重定向 POST 到新页面的最佳实践?

发布于 2025-01-04 09:54:49 字数 431 浏览 2 评论 0原文

我正在尝试解决如下所示的工作流程:(在 PHP 中)

  1. 用户在我的购物车中输入订单信息。
  2. 订单被捕获并存储到我的数据库中(没有信用卡信息)
  3. 用户被重定向到 Authorize.net 的 SIM 页面进行付款

当前设置:

shoppingcart.php - 收集用户送货信息/等

storeorder.php - 将订单存储在我的数据库,然后用适当的所需的authorize.net POST字段组装一个表单

简而言之,用户最终不得不查看一个不必要的中间页面,他们必须在其中单击“付款”表单提交按钮,然后将其发送给授权。网。

组合这些步骤的最佳实践是什么? (接收 POST,将信息存储在我的数据库中,然后使用新的 POST 字段自动重定向到authorize.net,无需任何用户交互)

I am trying to solve a workflow that looks something like this: (in PHP)

  1. User enters order information in my shopping cart.
  2. The order is captured and stored to my database (w/o credit card info)
  3. The user is redirected to authorize.net's SIM page for payment

Current setup:

shoppingcart.php - collects user shipping information/etc

storeorder.php - stores the order in my database, and then assembles a form with the appropriate required authorize.net POST fields

In short, the user ends up having to view an unnecessary intermediate page where they have to click a "Make Payment" form submit button which then sends them to authorize.net.

What is the best practice for combining these steps? (receiving a POST, storing info in my DB, and then auto-redirecting to authorize.net with new POST fields without any user interaction)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深爱不及久伴 2025-01-11 09:54:49

不要干扰用户的资金!
即使您不想存储信用卡详细信息,您的网站也可能会被黑客攻击,攻击者也会得到它。

  1. 用户在我的购物车中输入订单信息。
  2. 订单通过authorize.net 的SIM 卡付款页面进行处理
  3. 。authorize.net 请联系您的网站并提供付款详细信息。

这是唯一正确的方法。
世界上每个网站都是这样运作的。所以你必须这样做。别以为自己是个聪明的王牌。

DO NOT INTERFERE WITH USER's MONEY!
Even if you don't want store the credit card details, your site can be hacked and an attacker would get it.

  1. User enters order information in my shopping cart.
  2. The order is processed via authorize.net's SIM page for payment
  3. authorize.net contact your site with payment details.

is the onlly proper way.
EVERY site in the world works this way. So you have to. Don't take yourself a smart ace.

爱给你人给你 2025-01-11 09:54:49

shoppingcart.php 上,您可以放置​​一个结帐按钮。按下后即提交用户操作。 不要在隐藏字段中保存商品价格/数量。在用户结帐按钮的 POST 上,您可以将所有信息保存在数据库中,并在 PHP Post 条件中创建一个 HTML 表单来设置授权值.net 并将您的标题重定向到付款页面。

On shoppingcart.php you can place a button for Checkout. On pressing that the User action is submitted. Do not save item prices/quantity in hidden fields. on the POSTing of the user checkout button you can save all the info in your DB and make an HTML form in the PHP Post condition to set values for authorize.net and redirect your header to the PAYMENT page.

独守阴晴ぅ圆缺 2025-01-11 09:54:49

用户是否必须在authorize.net 页面上进行任何类型的输入,或者您的表单是否提供了所有需要的信息?如果您生成所有信息,那么最简单的方法是通过 cUrl 调用authorize.net 将数据直接推送给它们并检查返回状态代码/输出以查看是否成功/失败等。

如果用户仍需要使用以下方法输入账单详细信息。

表单发布到 /somepage.php

somepage.php 运行它的处理,并在处理完成后一直在底部添加 header("Location: https://www.authorize.net/do paymenthere");

确保您仍然回显此页面上的“付款”按钮,以防万一用户做了一些奇怪的事情,强制重定向停止等。这样,它看起来不像损坏的代码,但对于少数例外情况,对他们的浏览器做一些不寻常的事情等等,你仍然可以优雅地处理它们

PS:这只能通过将 post 变量连接为 get 请求来工作,假设authorize.net 会将 get 请求作为变量处理。

在不使用 get 请求的情况下执行此操作的真正简单方法是使用 javascript 通过在 dom 上提交表单准备好...这样您就可以向用户显示处理订单消息。并将它们与嵌入的隐藏表单直接发布到authorize.net,以防您的处理时间比预期的时间长等。

在processing.php页面上的jquery术语中,您会看到如下内容:

echo $form; // HTML form with all it's values required by authorize.net
echo "<h1>Processing your request</h1>";
<script type='text/javascript'>$(document).ready(function(){$('#hiddenformid').submit();});</script>

Does the user have to do any type of input on the authorize.net page or does your form supply all the needed information? If you generate all the information then the easiest way to do it is via a cUrl call to authorize.net pushing the data directly to them and checking the return status code / output to see if it was a success / not etc.

If the user needs to still enter billing details use the following method.

Form posts to /somepage.php

somepage.php runs it's processing and all the way at the bottom once processing is completed add header("Location: https://www.authorize.net/dopaymenthere");

make sure you still echo the make payment button on this page, just in case the user does something wacky out of the ordinary where they force redirects to stop etc. That way it doesn't look like broken code, but for the few exceptions that do out of the ordinary things to their browsers etc you can still handle them gracefully

PS: this would only work by concatenating the post variables as get requests, assuming that authorize.net would handle the get requests as variables.

The really easy way to do this without using a get request is with javascript by submitting the form on dom ready... that way you can show a processing order message to the user. and post them with an embedded hidden form directly to authorize.net in case your processing takes longer than expected etc.

In jquery terms on the processing.php page you would have something like:

echo $form; // HTML form with all it's values required by authorize.net
echo "<h1>Processing your request</h1>";
<script type='text/javascript'>$(document).ready(function(){$('#hiddenformid').submit();});</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文