Organizational Research By

Surprising Reserch Topic

codeigniter users login check


codeigniter users login check  using -'session,codeigniter,login'

I'm a novice with Code Igniter and I'm currently building my own user system. I'm curretly on the login process and I have implemented a check for whether a user is currently logged in or not.

In my header I then want to display a link to 'Log Out' if they are already logged in, or 'Log In' if they are not logged in currently.

I have a working function in my index controller as follows, the $loginstatus variable is sent to the my page header view:

function check_session()
{
    //Check session status

            $session = $this->session->userdata('login_state');

            $default = "Log In";

            if ($session == 1)
            {
                $url = site_url('index.php/users/logout');
                $status = "Log Out";



            }
            else
            {
                $url = site_url('index.php/users/login');
                $status = $default;
            }

        $loginstatus = array(
                        "url" => $url,
                        "status" => $status
                        );

        return $loginstatus;
}


Because it is currently only in the index controller the $loginstatus is not generated for the header view for other pages and this is my problem.

Where would I put this function so that it always loads before my header? I tried creating a libary with a 'Common' class and then autoloading that but I ended up with lots of problems.

Thanks in advance.
    
asked Sep 15, 2015 by LorZ01
0 votes
8 views



Related Hot Questions



Government Jobs Opening


...