Reputation: 19
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.
Upvotes: 1
Views: 6790
Reputation: 23379
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
Upvotes: 2
Reputation: 4770
You can't retransmit your variables via POST if you are using header function of php.
You have 2 alternatives here:
Upvotes: 2
Reputation: 73
You need to pass the variables in the query string of the url you are redirecting to.
See http://www.php.net/manual/en/function.http-build-query.php
Upvotes: 2