Session problem in CodeIgniter 3.0.4

1

I am implementing a login system using codeigniter 3, however the following problem is occurring, when I log in normally on the system it redirects me to login page again, as a result of not being able to create the session, but when I do login a second time works perfectly. Following is the code

login method

 public function logar_empresa(){
    $this->load->library('form_validation');
    //regras do formulario
    $this->form_validation->set_rules('email', 'Email', 'required');
    $this->form_validation->set_rules('senha', 'Senha', 'trim|required|callback_auth_check_empresa');
    $this->form_validation->set_error_delimiters('<br/><span class="label label-danger error">','</span>');
    if($this->form_validation->run() == FALSE){
        $this->load->view('admin/login');
    }else{
        //$this->index();
        redirect('painel/home','location');
    }
}

login callback method

    function auth_check_empresa($senha)
    {

    $login = $this->input->post('email');
    $result = $this->empresa_model->validar($login, $senha);
    //print_r($result);
    $sess_array = null;
    if($result)
    {
        foreach($result as $row) {
            $sess_array = array(
                'id' => $row->id_empresa,
                'nome' => $row->nome_empresa,
                'logo' => $row->logo,
                'tipo' => 1,
                'email' => $row->email,
                'logado' => true
            );
        }
        $this->session->set_userdata('empresa_logado', $sess_array);
        return true;
    }
    else
    {
        $this->form_validation->set_message('auth_check_empresa', 'Login ou Senha Invalido!');
        return false;
    }

}

Session Settings

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
    
asked by anonymous 25.02.2016 / 23:30

0 answers