tags:

views:

109

answers:

3

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.

+1  A: 

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

webdestroya
A: 

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
I want it to be invisible for the user that I send some vars. Sessions may show up in the url.
Alex Polo
You will want to quote `post_array`.
Artefacto
@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.
Col. Shrapnel
I am not going to tell the whole story. It's too long and uninteresting.
Alex Polo
While true that you should quote `post_array` you are not required to.
Geek Num 88
@Geek `define('post_array', 'foo')` - Woops. You *are* required to quote strings if you mean strings.
deceze
A: 

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

<form id="f" method="post" action="http://example.com"&gt;
<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
Yeah, I knew I could it via JS. Though, thanks anyway.
Alex Polo