CodeIgniter Forums
Problem keep connected - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Problem keep connected (/thread-43850.html)

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:

//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

Can anyone help me in doubt I have?!

Thanks a lot!

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

Make it a function and call it in your controllers constructor.