Session is destroyed after redirect in Codeigniter 3

1

Developing a login system, I wrote the following script in the controller:

    $usuario = $this->input->post('usuario');
    $senha = $this->input->post('uenha');
    $q = $this->login->logar($usuario, $senha);
    if (!$q):
        $this->session->set_userdata('logado',false);
        redirect('login');
    endif;
    $this->session->set_userdata('logado',true);
    redirect('redacoes');

This is an example.

It turns out that after the redirect to another controller, the sessions are not being stored.

Note: I loaded the autoload.

    
asked by anonymous 14.10.2016 / 16:15

1 answer

2

Try this:

$logar = $this->login->logar($this->input->('usuario'), $this->input->post('senha'));

if($logar){
    $this->session->set_userdata('logado', "OK");
    redirect('redacoes');
} else {
    $this->session->set_userdata('logado', false);
    redirect('login');
}
    
14.10.2016 / 17:35