Why does this `$_SESSION = $_POST` fail?

后端 未结 4 609
粉色の甜心
粉色の甜心 2021-01-28 06:04

What am I missing here? This is my PHP file:

\";
echo print_r($_POST);

// Save input in sessio         


        
相关标签:
4条回答
  • 2021-01-28 06:06

    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.

    0 讨论(0)
  • 2021-01-28 06:09

    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

    0 讨论(0)
  • 2021-01-28 06:12

    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.

    0 讨论(0)
  • 2021-01-28 06:27

    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.

    0 讨论(0)
提交回复
热议问题