-4

What I want to do is when user goes to one page I redirect him to another page while sending some post variables to this latter page.

Alex Polo
  • 905
  • 9
  • 21
  • possible duplicate of [PHP Redirection with Post Parameters](http://stackoverflow.com/questions/2865289/php-redirection-with-post-parameters) – Mike B May 31 '10 at 04:49
  • Why do you need to `POST` to another page? Do you control this page? If so what does this page do with the `POST` data? – rojoca May 31 '10 at 06:04
  • 4
    Is it just me or does this actually smell like a "how to do phishing" question? – wimvds May 31 '10 at 08:48

3 Answers3

1

You can't redirect a user and simultaneously send any POST data.

Mitch Dempsey
  • 38,725
  • 6
  • 68
  • 74
0

While it is true you cannot send variables into the $_POST array while redirecting you can use sessions to store the data and then redirect.

so

session_start();

$_SESSION['post_array'] = $_POST;

header("Location: next_page.php");

Then on next_page.php

session_start();

$_SESSION['post_array'] contains all the post variables from the previous page

Geek Num 88
  • 5,264
  • 2
  • 22
  • 35
0

You can't do it with just PHP. It's possible with Javascript however:

<form id="f" method="post" action="http://example.com">
<input type="hidden" name="var1" value="value1" />
<input type="hidden" name="var2" value="value2" />
</form>
<script type="text/javascript">
window.onload = function () {
   document.getElementById('f').submit();
}
</script>

You might want to load the values and names with PHP.

DXL
  • 149
  • 4