Reputation: 1
My program is basically a form. After the user presses the submit button, the program does input error checking (so I can't use the action element in form to call a new program). After error checking I call another program using header("Location: url")
.
The problem is I lose all my session data. I have session_start()
as the first line in both programs, I use $_SESSION['variable name']
to name some variables. My form uses the POST method.
My POST variables exist after the user presses submit but they are lost also after the header()
call - along with my $_SESSION['']
variables. My session_id is the same for both programs. I have tried session_write_close()
just before the header()
statement - still lose the data.
How do I keep my variable data?
Upvotes: 0
Views: 1054
Reputation: 1455
When you assign those session variable .. try to echo them on the same page without the header and see it they are assigned properly.
and make sure your use exit() right after the header call. If you don't it still runs the rest of the script after redirecting you. it might be resetting the session variable since $_POST will be empty then.
let me know if it works
Upvotes: 0
Reputation: 478
Before you use your header, stock the content of your $_POST into a $_SESSION variable. The $_POST variables aren't saved if you go from page 1 --> 2 --> 3, they are sent from page 1 to page 2, that's it.
Or 2nd option : when you do the header you can put the content of your post into the url to do something like :
header("Location: http://www.example.com/index.php?name=".$_POST['name']);
And the when after the header when you land on your page you can use :
$name = $_GET['name'];
And you'll get the name for instance.
edit : ty for fixing my english :)
Upvotes: 1