Possible Duplicate:
PHP header() redirect with POST variables
I'm writing a script where form data is being submitted to another script. I want the second script to perform some error-checking on the submitted $_POST
data, and if everything is okay, process the data. If the data has errors, I'm using header('Location: http://www.example.com/script.php');
to return the visitor back to the form page.
The issue I'm having is that I want the form to be sticky - fields with correct data maintain the values the user put in them. Obviously, to get those values, I need access to the $_POST
array. However, this seems to be destroyed when the header()
call forwards the visitor back to the form.
Is there any way to use the header Location stuff to redirect the visitor to another page, while still preserving the $_POST
data?
Now I'm using like this : header('Location: http://www.example.com/add.php?id='.$id.'&name='.$name.'&code='.$code.'&desc='.$description.'');
and accessing as $_GET
.
For the same can I use and kind of POST in header('location: xxx')
??
the best way to achieve this 'sticky form' is to use a session.
<?php
session_start();
$_SESSION = $_POST;
//do error checking here
//if all is valid
session_write_close();
header('Location: *where you want your form to go*');
die;
?>
and on the redirect page you can use them like so:
<?php
session_start();
//use $_SESSION like you would the post data
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With