1
I have a query that returns the accesses of the user who just logged in. I need to turn them into an array and store them in a session and a cookie. Follow code:
//ARMAZENA AS PERMISSOES DO PERFIL DO USUARIO
if($sql_permissoes->rowCount() > 0){
$permissao_visualizacao = array();
$permissao_alteracao = array();
foreach ($sql_permissoes as $sql_permissoes_row) {
$permissao_visualizacao[] = $sql_permissoes_row["url_localizacao"];
$permissao_alteracao[] = $sql_permissoes_row["permite_alteracao"];
}
}
$_SESSION["ged.permissao.visualizacao"] = $permissao_visualizacao;
$_SESSION["ged.permissao.alteracao"] = $permissao_alteracao;
setcookie("ged.permissao.visualizacao", $permissao_visualizacao, mktime(0, 0, 0, date("m"), date("d")+5, date("Y")) );
setcookie("ged.permissao.alteracao", $permissao_alteracao, mktime(0, 0, 0, date("m"), date("d")+5, date("Y")) );
But in the setcookie lines I get the following message:
Warning: setcookie() expects parameter 2 to be string, array given.
What is the most recommended method of doing this operation?
It might work, but remember browsers may have limitations on storage size, maybe it’s best to store in server sessions and use the cookie only to identify which session is whose (the same
session_*
already does this).– Guilherme Nascimento