• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem keep connected

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

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

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.