CodeIgniter Forums

Full Version: Problem keep connected
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Halan Batista[/eluser]
Hello World?

I am creating a login system where the user can choose to stay connected.

I'm making cookie, only when the page loads I need it to check if the cookie is set, but I do not know how I can do to make this code to run on startup:

Code:
//verifica se existe cookie de sessão
        if (isset($_COOKIE["id_usuario"]) && isset($_COOKIE["codigo_cookie"]) && ($this->session->userdata('logged_in') == FALSE)){
                
                //verifica se cookie está gravado no sistema e pega dados do usuário
                $query = $this->db->select('id_usuarios, nome, email, codigo_socio, cookie')->where('cookie', $_COOKIE["codigo_cookie"])->get('usuarios');
                $user = $query->row();
                
                //se encontrou o usuário, loga automaticamente no sistema
                if($user) {
                
                    if($user->codigo_socio != 0) {    $socio = "s"; } else { $socio = "n"; }
                    
                    $newdata = array(
                           'id_user'     =>  $user->id_usuarios ,
                           'nome'        =>  $user->nome ,
                           'email'       =>  $user->email,
                           'socio'       =>  $socio,                      
                           'logged_in'   => TRUE
                       );              
                    
                    $this->session->set_userdata($newdata);
                    $this->logged_in();                
                    exit;        
                }
        
        }

Can anyone help me in doubt I have?!

Thanks a lot!

El Forum

[eluser]InsiteFX[/eluser]
Make it a function and call it in your controllers constructor.

InsiteFX