PHP重定向与POST数据 [英] PHP Redirect with POST data

查看:258
本文介绍了PHP重定向与POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此主题进行了一些研究,有些专家说它不是

I did some research on this topic, and there are some experts who have said that it is not possible, so I would like to ask for an alternative solution.

我的情况:

页面A:[checkout.php]客户填写帐单明细.

Page A: [checkout.php] Customer fills in their billing details.

B页:[process.php]生成发票编号并将客户详细信息存储在数据库中.

Page B: [process.php] Generate an invoice number and store customer details in database.

C页:[thirdparty.com]第三方付款网关(仅接受过帐数据).

Page C: [thirdparty.com] Third Payment Gateway (ONLY ACCEPT POST DATA).

客户填写其详细信息,然后在A页中设置购物车,然后在B页中进行POST.在process.php中,将POSTED数据存储在数据库中并生成发票编号.之后,将客户数据和发票号过帐到thirdparty.com付款网关.问题是在页面B中执行POST.cURL能够将数据发布到页面C,但是问题是页面未重定向到页面C.客户需要在页面C上填写信用卡详细信息.

Customer fills in their details and sets up their cart in Page A, then POSTs to Page B. Inside process.php, store the POSTed data inside the database and generate an invoice number. After that, POST the customer data and invoice number to thirdparty.com payment gateway. The problem is doing POST in page B. cURL is able to POST the data to Page C, but the problem is the page didn't redirect to page C. The customer needs to fill in Credit Card details on Page C.

第三方付款网关确实给了我们API示例,该示例是将发票编号与客户详细信息一起过帐. 我们不希望系统生成多余的发票编号.

The third party payment gateway did give us the API sample, the sample is POST the invoice number together with customer detail. We don't want the system to generate an excess of unwanted invoice numbers.

有什么解决办法吗? 我们当前的解决方案是让客户在A页中填写详细信息,然后在B页中创建另一个页面,在其中显示所有客户详细信息,用户可以单击CONFIRM按钮以发布到C页.

Is there any solution for this? Our current solution is for the customer to fill detail in Page A, then in Page B we create another page showing all the customer details there, where the user can click a CONFIRM button to POST to Page C.

我们的目标是让客户只需单击一次即可.

Our goal is for customers to only have to click once.

希望我的问题很清楚:)

Hope my question is clear :)

推荐答案

在页面B上生成一个表单,并将所有必需的数据和操作设置为页面C,然后在页面加载时使用JavaScript提交表单.您的数据将被发送到C页,而不会给用户带来太多麻烦.

Generate a form on Page B with all the required data and action set to Page C and submit it with JavaScript on page load. Your data will be sent to Page C without much hassle to the user.

这是唯一的方法.重定向是一个303 HTTP标头,您可以在 http://www上阅读. w3.org/Protocols/rfc2616/rfc2616-sec10.html ,但我会引用其中的一些内容:

This is the only way to do it. A redirect is a 303 HTTP header that you can read up on http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html, but I'll quote some of it:

对请求的响应可以是 在不同的URI下找到,应该 使用GET方法检索 该资源.该方法存在 主要是为了允许输出 POST激活的脚本以重定向 选定资源的用户代理.这 新URI不能替代参考 原始请求的资源. 303响应一定不能被缓存, 但是对第二个的回应 (重定向)请求可能是 可缓存的.

The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. The 303 response MUST NOT be cached, but the response to the second (redirected) request might be cacheable.

实现您正在做的事情的唯一方法是使用一个将用户引导到页面C的中间页面.以下是有关如何实现此目标的小片段/简单片段:

The only way to achieve what you're doing is with a intermediate page that sends the user to Page C. Here's a small/simple snippet on how you can achieve that:

<form id="myForm" action="Page_C.php" method="post">
<?php
    foreach ($_POST as $a => $b) {
        echo '<input type="hidden" name="'.htmlentities($a).'" value="'.htmlentities($b).'">';
    }
?>
</form>
<script type="text/javascript">
    document.getElementById('myForm').submit();
</script>

您还应该在noscript标记内使用一个简单的确认"表单,以确保没有Javascript的用户能够使用您的服务.

You should also have a simple "confirm" form inside a noscript tag to make sure users without Javascript will be able to use your service.

这篇关于PHP重定向与POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆