如何从php脚本发送重定向页面传递变量作为post变量 [英] how to send redirect page pass variables as post variables from a php script
问题描述
你可以在这里找到类似的问题在POST请求中的PHP Post请求但这在我的上下文中不起作用。
我有一个表格(旅游网站的预订表格),当提交表格时,会处理这些值在验证和计算值以及发送电子邮件等脚本中。
处理完变量后,我想将其发送到页面进行付款,此页面将发布付款详细信息Paypal。
我的问题是在提交预订表格后,处理从预订中检索到的值后,如何以变量将重定向的方式重定向页面作为后期变量传递。 (我不是从另一种形式的回复看,我想重定向到另一种形式)。
创建一个POST请求,使用fsockopen()打开与主机的TCP连接,然后在fsockopen()返回的处理程序上使用fwrite(),其值与OP中的头函数中使用的值相同。或者,您可以使用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);
?>
其中$ Message是你的变量。
<编辑:我很久以前回答这个问题也许我忘了引用php.net,但这里是每个评论的链接 http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html 作为参考
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).
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
这篇关于如何从php脚本发送重定向页面传递变量作为post变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!