1

The following code will let me redirect the page to a new location, and take the GET variables with me..

<?php
// set GET variables
$name="John";
$email="me@there.com"
// redirect the page
header("Location: ../process.php?name=$name&email=$email");
?>

How can I do exactly the same thing and take POST variables with me?

I need to do this to simulate another page that has a form and submit button on it. Normally, on that page, the user would press the submit button and the POST data would be sent to process.php. I need my new page, after performing some processing, to re-direct to process.php with the POST data. This needs to happen without anyone pressing a button.

I can't use sessions, as the page I am simulating does not do this - it just sends the POST data when the submit button is pressed.

I can't use javascript as there is no-user interaction to press a button - it is purely a program-branch that will cause this to happen.

I don't mind using curl or JQuery, but haven't been able to figure out how to do it from the code I have already found. I would be very grateful for a working example, please.

Tripp Kinetics
  • 5,178
  • 2
  • 23
  • 37
Tim Makins
  • 394
  • 4
  • 12
  • possible duplicate of [Apache 301 Redirect and preserving post data](http://stackoverflow.com/questions/13628831/apache-301-redirect-and-preserving-post-data) – Giacomo1968 Jun 17 '14 at 20:30
  • 1
    I marked this as duplicated, but found a great answer where it seems if you can redirect with a `307` POST data is preserved. http://programmers.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect#99966 – Giacomo1968 Jun 17 '14 at 20:31
  • 1
    There's also this question: [PHP Redirection with Post Parameters](http://stackoverflow.com/questions/2865289/php-redirection-with-post-parameters). According to the accepted answer to that question, it's not possible from the server. – Kryten Jun 17 '14 at 20:32
  • @Kryten I think the overall answer is it might be doable, but it’s no a consistent practice so one should assume that a redirect will lose post data. – Giacomo1968 Jun 17 '14 at 20:36
  • Hi - this is not a duplicate. I have read those answers and they do not answer my question. I have seen some posts that say this can be done cURL, but I can't get it to work. If anyone knows how to do it in this way, please reply. – Tim Makins Jun 17 '14 at 23:35

1 Answers1

0

Please try this code.

<form name="myForm" id="submit" action="test.php" method="POST">
    <p>
        <input name="name" value="John" />
         <input name="email" value="me@there.com" />
    </p>
    <p>
        <input type="submit" value="Submit" />
    </p>
</form>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(function(){
    $("#submit").submit();
});
</script>