Welcome Guest, Not a member yet? Register   Sign In
Problem keep connected

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

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


Theme © iAndrew 2016 - Forum software by © MyBB