javascript - PHP forward POST variables to other page - Stack Overflow

I have html form and I have to submit that form on same page where's that form, add POST variable

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
Add a ment  | 

3 Answers 3

Reset to default 2

You 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:

  1. convert $_POST in $_GET (for example http_build_query)
  2. 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

相关推荐

  • javascript - PHP forward POST variables to other page - Stack Overflow

    I have html form and I have to submit that form on same page where's that form, add POST variable

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信