I'm having a really weird issue saving form values submitted through $_POST as session variables.
OK, so I have a form on page 1 which submits to page 2.
On page 2 I am setting all of the Post variables to Session variables.
On page 3 I am retrieving those variables.
On page 2 if I write something like this:
$_SESSION['fname'] = 'john';
It works fine. I can retrieve it on page 3.
If I write something like
$_SESSION['fname'] = $_POST['fname'];
That session variable is blank on page 3.
Even weirder, if I do something like:
$_SESSION['fname'] = $_POST['fname'].' Doe';
开发者_StackOverflow社区
On page 3 I see just Doe.
Session variables that were previously set by other pages are also fine on page 3.
I have verified that the post variables are set on page 2, and I'm at a loss at this point. I'm not a PHP session expert or anything, but I have worked with them before and haven't seen anything like this.
Anyone have any thoughts?
Edit: The variable is being set in the session, it's just blank on page 3.
that means that something in the post ($_POST['name']
) is not set;
try var_dump($_POST);
on page 2 too see what actually got posted
I can't resist asking: have you checked that method="POST"
and not GET
on the page 1 form?
I believe the issue is because the POST data is not available when the SESSION data is written.
You can probably fix it by opening your php.ini and making sure that POST is registered before SESSION, this way, POST is available when you try to write SESSION data.
精彩评论