Possible Duplicate:
How do you POST to a page using the PHP header() function?
For example, I need to redirect a user to a different page upon error, but I also want to POST a value to that page as well.
Possible Duplicate:
How do you POST to a page using the PHP header() function?
For example, I need to redirect a user to a different page upon error, but I also want to POST a value to that page as well.
You definitely cannot POST and redirect in the same time. Redirect means setting several HTTP headers. However, there are several solutions to your needs.
One is to store the data into $_SESSION and retrieve it from there, as answered above.
Another way is to put the form aside from PHP, in a separate file and include it if you have errors in the data posted, so you have all the variables in the current POST without the need to redirect the user (and set an error message in the form too).
You can think to use an AJAX to make the post and get the result back then you'll do the redirection using javascript.
Or, if there aren't many variables/values you want to pass you may use GET when doing the redirection.
I'm sure other alternatives exists too.
Could you use $_SESSION instead?
When a redirect is performed, a GET request is made. I don't believe it's possible to make a POST redirect.
You could modify your code to check for both POST and GET requests by using the
$_REQUEST
super global variable. That way, you can pass whatever parameters you need in the redirect as GET parameters and still have your PHP script pick them up.But, if you are working with a multi-step form, it might be a good idea to use session variables. This allows you to save the user's entered information from each step in the session, making it easy to load it again if they go back to a previous step.
In the action="" html tag just put the address you are redirecting them to. This will post the value to that page as well.