简体   繁体   English

通过POST发送数据,然后重定向到同一页面

[英]Send data via POST and then redirect to the same page

I've been reading a while before ask here but really need yours help on this topic. 在阅读这里的内容之前,我已经阅读了一段时间,但确实需要您提供有关此主题的帮助。 I found this amazing posts ([1],[2]) which is basically what I'm need but with some minor changes. 我发现了这些惊人的帖子([1],[2]),基本上是我所需要的,但有一些小的更改。 This is my flow: 这是我的流程:

  1. The user is buying products in my page 用户正在我的页面中购买产品
  2. The user end and start the process to pay and shipping 用户结束并开始付款和运输过程
  3. When the user arrive to the latest page before payment I have all the needed data to send via POST and to do online Payment 当用户在付款前到达最新页面时,我拥有通​​过POST发送并进行在线付款所需的所有数据
  4. In the other side exists a JSP which receive two parameters: total and invoiceNumber 另一方面,它有一个JSP,它接收两个参数:total和invoiceNumber

I know I need to use cURL in order to send data via POST but I need to redirect also to the bank online payment page. 我知道我需要使用cURL才能通过POST发送数据,但是我还需要重定向到银行在线支付页面。 How can I do this? 我怎样才能做到这一点?

PS: Sorry for my english is not so good PS:对不起,我的英语不太好

[1] PHP - Redirect and send data via POST [2] http://davidwalsh.name/execute-http-post-php-curl [1] PHP-通过POST重定向和发送数据 [2] http://davidwalsh.name/execute-http-post-php-curl

在PHP中,您可以使用以下语句重定向用户:

header("Location: <your location>");
if($_POST['youFormName'])
 {
 //whatever you do with your post data do here first then:
 header("Location: <your location>");
 exit;
 }


First of all welcome to Stack Overflow . 首先,欢迎使用Stack Overflow

if all data is on your page then no need to use CURL. 如果所有数据都在您的页面上,则无需使用CURL。 CURL is for cross domain. CURL用于跨域。 if u want to post and redirect on same page then do the action on same page ($_SERVER['PHP_SELF']) ; 如果您要在同一页面上发布和重定向,则在同一页面上执行操作($_SERVER['PHP_SELF']) that's it.. make your page this way 就是这样..使您的页面这样

if(isset($_POST)){
// do all the process with your post data
}
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="shoppingForm">
//here is your  form detail
</form>

Note: PHP manual is best to learn 注意:最好学习PHP手册

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

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