What am I missing here? This is my PHP file:
session_start();
echo print_r($_SESSION);
echo \"
\";
echo print_r($_POST);
// Save input in sessio
Have you tried using $_SESSION['name'] = $_POST['name'];
instead?
I've never used $_SESSION = $_POST;
, and neither never seen it, in the whole time I programmed on PHP.
Hope this helps.
i would instead foreach
the $_POST and add it to $_SESSION['mypostvars']
. Keep in mind that you should validate and verify the $_POST before storing them.
this is a possible duplicated of PHP merge $_POST into $_SESSION
Working with Xampp, that example works just fine. The 'test1' is printed on the before and after a successful post. Using PHP 5.3.8.
Tested on Linux with PHP 5.3.6, also works fine printing the 'test1' in both cases.
So, it seems PHP is not the problem here.
You can modify $_SESSION but I don't think you're allowed to reassign it like that. Instead, copy the members of $_POST into it. Try using array_merge() but if that doesn't work then write a foreach loop to do it.