I have a class of Sessions in which every time I instantiate it, it automatically logs in.
When in another file I do I destroy the session through a method called doLogout
I see that it automatically deletes my session as expected but creates another one automatically without passing any parameters.
And the one that is created automatically has an entry named sidebar of value 1
that I do not know where they come from, because at no point in my code did I declare it.
Class
class sessao{
protected $id_ur;
protected $nvars;
public function __construct($inicia=true){
if($inicia==TRUE){
$this->start();
}
}
public function start(){
session_start();
$this->id_ur = session_id();
$this->setNvars();
}
private function setNvars(){
$this->nvars = sizeof($_SESSION);
}
public function getNvars(){
return $this->nvars;
}
public function setVar($var, $valor){
$_SESSION[$var] = $valor;
$this->setNvars();
}
public function unsetVar($var){
unset($_SESSION[$var]);
$this->setNvars();
}
public function getVar($var){
if(isset($_SESSION[$var])){
return $_SESSION[$var];
}else{
return NULL;
}
}
public function destroy($inicia=false){
session_unset();
session_destroy();
$this->setNvars();
if($inicia==TRUE){
$this->start();
}
}
public function printAll(){
foreach ($_SESSION as $k => $v){
printf("%s = %s<br />", $k, $v);
}
}
}
?>
Function doLogout()
mentioned
public function doLogout(){
$sessao = new sessao();
$sessao->destroy(TRUE);
redireciona('index.php');
}