CodeIgniter Forums
Problem keep connected - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem keep connected (/showthread.php?tid=43850)



Problem keep connected - El Forum - 07-25-2011

[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!


Problem keep connected - El Forum - 07-25-2011

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

InsiteFX