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:");
}
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.
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./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.
Share Improve this question asked Apr 8, 2013 at 18:46 Haris MarošHaris Maroš 191 silver badge2 bronze badges 5-
You'd have to add
digest
to the URL (which of course would turn it into a GET variable, with length limits etc.) I don't think there is a way to do exactly what you want. (Actually I'm surprised that browsers re-post POST data to the new URL. Is this documented/expected?) – Pekka Commented Apr 8, 2013 at 18:49 - Look at stackoverflow./questions/653090/… – Heberfa Commented Apr 8, 2013 at 18:51
- 1 @Pekka웃: it may vary from browser to browser. See this post: stackoverflow./questions/46582/… – Alekc Commented Apr 8, 2013 at 18:52
- @Alekc thanks! That's useful info. – Pekka Commented Apr 8, 2013 at 18:53
- Before I answer, do you wish to send data to a file on the same server? then manipulate this on one page (located on the same server)? – Daryl Gill Commented Apr 8, 2013 at 19:09
3 Answers
Reset to default 2You need to pass the variables in the query string of the url you are redirecting to.
See http://www.php/manual/en/function.http-build-query.php
You can't retransmit your variables via POST if you are using header function of php.
You have 2 alternatives here:
- convert $_POST in $_GET (for example http_build_query)
- if it's essential for you to have this data to be transmitted as POST, you can create a blank page containing form with input type="hidden" and then just submit it with javascript. A bit ugly but should work.
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/manual/en/book.curl.php
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744393607a4572029.html
评论列表(0条)