I Have the following situation where I need add several values from $usuario to $_SESSION. Here's one way to do this however is cumbersome as $user has too many fields.
$_SESSION['logado_ecse'] = true;
$_SESSION['user'] = $usuario['login'];
$_SESSION['usuario_id'] = $usuario['id'];
$_SESSION['habilitada'] = $usuario['habilitada'];
$_SESSION['bloqueada'] = $usuario['desbloqueada'];
$_SESSION['administrador'] = $usuario['administrador'];
....
$_SESSION['auditor'] = $usuario['auditor'];
I was looking for a more elegant solution where in just one line I could do the same as for example something like this, but this solution doesn't work as expected.
$_SESSION = array_merge($usuario, $_SESSION);
The variable $usuario is as follows
echo gettype($usuario);
array
var_dump($usuario);
array (size=34)
'id' => string '1' (length=1)
0 => string '1' (length=1)
'login' => string 'admin' (length=5)
1 => string 'admin' (length=5)
'auditor' => string '0' (length=1)
2 => string '0' (length=1)
...
'telefone2' => string '11' (length=2)
14 => string '11' (length=2)
I like @KV's solution, I think I'm gonna implement it as a function. So far, my idea is that $_SESSION is a container to "the user", so a solution such as
$_SESSION['USER']=$usuario
will fragment the user's info in two
$_SESSION['some_name']
$_SESSION['USER']['some_name']
, not to mention that I'll have to reformat other parts of the code.
$_SESSION['USER']=$usuario;