PHP将POST变量转发到其他页面 [英] PHP forward POST variables to other page
本文介绍了PHP将POST变量转发到其他页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有html表单,我必须在同一页上提交表单,添加POST变量,然后所有变量传递到下一页。我试过这个:
< form method =POSTaction =>
< input type =TEXTname =names/>
< input type =TEXTname =email/>
< input type =submitname =send/>
< / form>
然后这个PHP代码:
if($ _ POST ['send']){
$ _POST ['digest'] =someText here;
头(HTTP / 1.0 307临时重定向);
标题(位置:https://nextpage.com/form);
}
但是当我重定向到另一个页面时,所有POST数据发送除了$ _POST ['digest']..我应该怎么做?
感谢您对英语不好的抱歉。 使用cURL。
$ fields_string =name =。$ _ POST ['name']。& email = 。$ _ POST ['email'];
$ url =您要发布的网站;
$ cx = curl_init();
curl_setopt($ cx,CURLOPT_URL,$ url );
curl_setopt($ cx,CURLOPT_POST,true);
curl_setopt($ cx,CURLOPT_POSTFIELDS,$ fields_string);
curl_setopt($ cx,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt ($ cx,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ cx,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ cx,CURLOPT_FOLLOWLOCATION,FALSE);
$ init_response = curl_exec($ cx);
curl_close($ cx);
http://php.net/manual/en/book.curl.php
I have html form and I have to submit that form on same page where's that form, add POST variable and then all variables pass to next page. I tried this:
<form method="POST" action="">
<input type="TEXT" name="names" />
<input type="TEXT" name="email" />
<input type="submit" name="send" />
</form>
and then this PHP Code:
if($_POST['send']){
$_POST['digest'] = "someText here";
header("HTTP/1.0 307 Temporary redirect");
header("Location:https://nextpage.com/form");
}
But when i get redirected to another page, all POST data are sent except "$_POST['digest']".. What should I do ?
Thanks and sorry for bad english.
解决方案
you need to use cURL for this.
$fields_string = "name=".$_POST['name']."&email=.$_POST['email'];
$url = "the website you want to post to";
$cx = curl_init();
curl_setopt($cx, CURLOPT_URL,$url);
curl_setopt($cx, CURLOPT_POST, true);
curl_setopt($cx, CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($cx, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($cx, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($cx, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cx, CURLOPT_FOLLOWLOCATION, FALSE);
$init_response = curl_exec($cx);
curl_close($cx);
http://php.net/manual/en/book.curl.php
这篇关于PHP将POST变量转发到其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文