Welcome Guest, Not a member yet? Register   Sign In
session problem , i want check session active and redirect to login page for all page
#4

This is how I do it, change to suit your needs.

PHP Code:
// Controller

/**
 * index ()
 * -------------------------------------------------------------------
 * Check to see if the Admin is logged in.
 * Else show the login view.
 */
public function index()
{
    // if the user is logged in.
    if (logged_in())
    {
        $this->auth->view('dashboard');
    }
    // show the login view.
    else
    {
        $this->auth->login();
    }
}

------------------------------------

// Auth Library

// -------------------------------------------------------------------

/**
 * logged_in ()
 * -------------------------------------------------------------------
 *
 * Check to see if a user is logged in
 *
 * Look in the session and return the 'logged_in' part
 *
 * @return bool
 */
public function logged_in()
{
    if ($this->CI->session->userdata('logged_in') === true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

-----------------------------------------------------

// Helper

// -----------------------------------------------------------------------

/**
 * logged_in
 */
if ( ! function_exists('logged_in'))
{
    /**
     * logged_in ()
     * -------------------------------------------------------------------
     *
     * @return bool
     */
    function logged_in()
    {
        $CI =& get_instance();

        if ($CI->auth->logged_in() == TRUE)
        {
            return TRUE;
        }

        return FALSE;
    }


With the auth_helper it makes it easy for me to use methods in the views for
checking users etc;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: session problem , i want check session active and redirect to login page for all page - by InsiteFX - 11-07-2019, 12:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB