Codeigniter 3.0 Library Session

Asked

Viewed 162 times

1

I made a function to log on to the system, however, when using the function sess_destroy() to destroy the session, it does not allow you to display the set_flashdata(). When I remove the function sess_destroy() the set_flashdata() works normally. Someone can give me a hint of what might 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');
}

1 answer

0


With CI 3, you just need to enter the array 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, the flashdate will not work on the next page. Destroy your session in your login method or keep the session data-free;

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');
    }
  • I put in my login method and it worked perfectly, Tanks ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.