Libraryign of Codeigniter 3.0

1

I made a function to log off the system, however, when I use the sess_destroy() function to destroy the session, it does not allow the set_flashdata() to be displayed. When I remove the function sess_destroy() the set_flashdata() works normally. Can anyone give me a hint of what it can be?

Controller:

public function logoff(){
    $this->session->unset_userdata(array('user_id' => '', 'user_nome' => '', 'user_admin' => '', 'user_logado' => ''));
    $this->session->sess_destroy();
    set_msg('logoffok', 'Logoff efetuado com sucesso!', 'sucesso');
    redirect('funcionario/login');
}
    
asked by anonymous 30.05.2015 / 00:36

1 answer

0

With CI 3, you just need to enter the array's keys to unset the variables: in your case:

$this->session->unset_userdata(array('user_id', 'user_nome', 'user_admin', 'user_logado'));

If you destroy the session, flashdata will not work on the next page. Destroy your session in your login method or leave the session with no data;

Here's an example I'm using:

    //construtor
    public function __construct() {
        parent::__construct();
        if(!$this->session->userdata('logado') && !in_array(uri_string(), array('admin/login', 'admin/autenticacao_json')))
            redirect(base_url('admin/login'));
    }

    //método de logoff
    public function logoff(){

        $this->session->unset_userdata(array('logado', 'id', 'nome', 'email'));

        $this->session->set_flashdata('aviso', '<div class="alert alert-info">Deslogado do sistema</div>');

        redirect(base_url('admin/login'));
    }

    //método de login
    public function login() {       
        if($this->session->userdata('logado')){            
            redirect(base_url('admin'));
        }

        //$this->session->sess_destroy();

        $this->load->helper('form');
        $this->load->view('admin/login');
    }
    
31.05.2015 / 16:33