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.
Asked
Active
Viewed 2,132 times
-4
-
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
-
4Is it just me or does this actually smell like a "how to do phishing" question? – wimvds May 31 '10 at 08:48
3 Answers
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
-
I want it to be invisible for the user that I send some vars. Sessions may show up in the url. – Alex Polo May 31 '10 at 04:46
-
1
-
2@dfjhdfjhdf you don't need to be invisible. You need to be **way** more specific when asking questions not having basic knowledge. What page, what data, what user, what's the reason to be "invisible". So, most experienced ones may phrase a real question for you. – Your Common Sense May 31 '10 at 05:02
-
I am not going to tell the whole story. It's too long and uninteresting. – Alex Polo May 31 '10 at 06:10
-
While true that you should quote `post_array` you are not required to. – Geek Num 88 May 31 '10 at 18:40
-
@Geek `define('post_array', 'foo')` - Woops. You *are* required to quote strings if you mean strings. – deceze Jun 04 '10 at 05:38
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