如何从php脚本发送重定向页面传递变量作为post变量

如何从php脚本发送重定向页面传递变量作为post变量

问题描述:

you can find a similar question here PHP Post Request inside a POST Request but this is not working in my context.

I have a form (reservation form for a tour website) and when the form is submitted, the values are processed in a script like validation and calculation of values and sending email.

after processing the variables, i want to send it to a page for payment and this page will post payment details to paypal.

My question is after the reservation form is submitted, after processing values retrieved from reservation from, how can i redirect the page in such a way that the variables will be passed as post variables. (I am not looking from response from the other form, i want to redirect to the other form).

您可以在此处找到类似的问题在POST请求中发布PHP请求但这在我的上下文中不起作用。 p>

我有一个表单 (旅游网站的预订表格),当提交表格时,将在脚本中处理这些值,如验证和计算值并发送电子邮件。 p>

处理变量后,我想要 将其发送到付款页面,此页面将付款详细信息发送到paypal。 p>

我的问题是在提交预订表格后,处理从预订中检索到的值后,我该怎么办? 以这样的方式重定向页面,使变量作为post变量传递。 (我不是从另一种形式的回复看,我想重定向到另一种形式)。 p> div>

To create a POST request, open a up a TCP connection to the host using fsockopen(), then use fwrite() on the handler returned from fsockopen() with the same values you used in the header functions in the OP. Alternatively, you can use cURL.

<?php
 if(isset($_POST['Name']))     $Name   = $_POST['Name'];
 if(isset($_POST['Email']))   $Email   = $_POST['Email'];
 if(isset($_POST['Message']))   $Message= htmlentities($_POST['Message']);

 $Curl_Session = curl_init('http://www.yoururl.com/script.php');
 curl_setopt ($Curl_Session, CURLOPT_POST, 1);
 curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "Name=$Name&Email=$Email&Message=$Message");
 curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
 curl_exec ($Curl_Session);
 curl_close ($Curl_Session);
?>

Where $Message would be your variables.

EDIT: i answered this long ago maybe i did forget to reference from php.net but here is the link per comment http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html as Reference

You can't. HTTP makes no provisions for redirecting with anything in the request body (which is where POST data goes). You can only redirect with a GET request. So the typical way to do this is to take the user to a second page that has a button to "Continue to PayPal", or something of that nature. That button POSTs all the data to PayPal as normal.

For what it's worth, if this is for the PayPal "Buy Now" button, they actually (even if not documented) allow sending all those form variables in the GET request, via the URL. We do this in one of our applications where we "track" the start of the payment process and then redirect to a PayPal URL containing all the form fields as a query string, then "complete" the transaction as the user returns.

Well, I suppose that if you are talking about keeping data in your own website between pages you need to use PHP's session functions

To start the session just do session_start();

and to add session vars just use the superglobal array $_SESSION['myvar'] = $value; you can then read them through the same means print_r($_SESSION[]);

However if you are talking about sensing data with the paypal API I highly recommend looking at their developer API manual.

Hope that helps, RayQuang