System logs alone in any action

Asked

Viewed 126 times

2

Gentlemen, In my Administrative system I log in normal... However, any action within the system, it logs out alone... Without clicking on anything logout... Would anyone like to describe me if you’ve ever had this kind of problem? Just in case, I’m putting the Controller here.

Controller

public function verificarLogin(){

    $this->load->library('form_validation');
    $this->form_validation->set_rules('email','Email','valid_email|required|xss_clean|trim');
    $this->form_validation->set_rules('senha','Senha','required|xss_clean|trim');
    $ajax = $this->input->get('ajax');
    if ($this->form_validation->run() == false) {

        if($ajax == true){
            $json = array('result' => false);
            echo json_encode($json);
        }
        else{
            $this->session->set_flashdata('error','Os dados de acesso estão incorretos.');
            redirect($this->login);
        }
    } 
    else {

        $email = $this->input->post('email');
        $senha = $this->input->post('senha');

        $this->load->library('encrypt');   
        $senha = $this->encrypt->sha1($senha);

        $this->db->where('email',$email);
        $this->db->where('senha',$senha);
        $this->db->where('situacao',1);
        $this->db->limit(1);
        $usuario = $this->db->get('usuarios')->row();
        if(count($usuario) > 0){
            $dados = array('nome' => $usuario->nome, 'id' => $usuario->idUsuarios,'permissao' => $usuario->permissoes_id , 'logado' => TRUE);
            $this->session->set_userdata($dados);

            if($ajax == true){
                $json = array('result' => true);
                echo json_encode($json);
            }
            else{
                redirect(base_url().'administrar');
            }


        }
        else{


            if($ajax == true){
                $json = array('result' => false);
                echo json_encode($json);
            }
            else{
                $this->session->set_flashdata('error','Os dados de acesso estão incorretos.');
                redirect($this->login);
            }
        }

    }

}

Observing

Within the system I have a controller and a model that manages to Add/Edit/Remove within the user table... maybe it has something to do with this logout... If anyone can help me, I’m grateful.

Request to Log in

    if((!$this->session->userdata('session_id')) || (!$this->session->userdata('logado'))){
        redirect('administrar/login');
    }

Result of print_r()

[userdata] => Array
    (
        [session_id] => 11bd5976ec8ec9d15de1f29277bb4e61
        [ip_address] => 201.10.93.25
        [user_agent] => Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36
        [last_activity] => 1436637190
        [user_data] => 
        [nome] => Administrador
        [id] => 1
        [permissao] => 1
        [logado] => 1
    )

1 answer

0

I’ve had this problem with codeigniter (and you will always have problems with it) when I set up the session to be saved as cookie.

Change the option of cookie for database. I believe the problem is cookie only contain a certain amount of data.

Browser other questions tagged

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