Welcome Guest, Not a member yet? Register   Sign In
Sessions expiring after browser closes
#9

[eluser]AgentPhoenix[/eluser]
[quote author="mattpointblank" date="1257814818"][quote author="AgentPhoenix" date="1257811544"]When they get to the site, the constructor has a call to a method in the library that checks to see if they're logged in.[/quote]

This is the part I can't get my head round - how are you calling that method when someone loads your site?[/quote]

In my constructor, I have a line of code that checks whether or not a user is logged in. The constructor looks like this (non-relevant parts removed):
Code:
function Main_base()
{
    parent::Controller();
    
    ...
    
    /* check to see if they are logged in */
    $this->auth->is_logged_in();

    ...
}

Then, in my authentication library, I have a method called is_logged_in that looks like this:
Code:
function is_logged_in($redirect = FALSE)
{
    /* get an instance of CI */
    $this->ci =& get_instance();
    
    if ($this->ci->session->userdata('player_id') === FALSE)
    {
        $auto = $this->_autologin();
        
        if ($auto !== FALSE)
        { /* if the autologin was successful */
            return TRUE;
        }
        
        if ($redirect === TRUE)
        {
            redirect('login/index/error/1');
        }
        else
        {
            return FALSE;
        }
    }
    
    return TRUE;
}

As you can see here, if the user isn't logged it, in tries to do an autologin through the following private method:
Code:
function _autologin()
{
    /* get an instance of CI */
    $this->ci =& get_instance();
    
    /* load the resources */
    $this->ci->load->model('system_model', 'sys');
    
    /* load the CI resources */
    $this->ci->load->helper('cookie');
    
    /* grab unique identifier */
    $uid = $this->ci->sys->get_uid();
    
    /* get the cookie */
    $cookie = get_cookie($uid, TRUE);
    
    if ($cookie !== FALSE)
    {
        $login = $this->login($cookie['email'], $cookie['password']);
        
        return $login;
    }
    
    return FALSE;
}
From here, I simply pull the system unique ID (which is how the cookie is named) and then pass the email and password parameters to the login method which then check those values against what's in the database and goes from there.


Messages In This Thread
Sessions expiring after browser closes - by El Forum - 11-09-2009, 06:13 AM
Sessions expiring after browser closes - by El Forum - 11-09-2009, 06:30 AM
Sessions expiring after browser closes - by El Forum - 11-09-2009, 07:09 AM
Sessions expiring after browser closes - by El Forum - 11-09-2009, 10:52 AM
Sessions expiring after browser closes - by El Forum - 11-09-2009, 12:05 PM
Sessions expiring after browser closes - by El Forum - 11-09-2009, 12:17 PM
Sessions expiring after browser closes - by El Forum - 11-09-2009, 01:00 PM
Sessions expiring after browser closes - by El Forum - 11-09-2009, 01:24 PM
Sessions expiring after browser closes - by El Forum - 11-09-2009, 02:21 PM
Sessions expiring after browser closes - by El Forum - 11-10-2009, 05:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB