Welcome Guest, Not a member yet? Register   Sign In
Sessions not saving...
#1

[eluser]RBrowne[/eluser]
I've been building a system that requires a user login and I've run into a problem.

My authentication lib sets some data into the session cookie (not storing to DB) but when the dashboard page loads it's lost.

Here's the code for logging in:

Code:
function login()
    {
        // Validation
        // Set rules
        
        $this->CI->form_validation->set_error_delimiters("<span class='error'>", "</span>");
        
        
        $this->CI->form_validation->set_rules('username', 'Username', 'required');
        $this->CI->form_validation->set_rules('password', 'Password', 'required');

        if ($this->CI->form_validation->run() === false)
        {
            $sRedirect = $this->CI->input->post('redirect');
            if (empty($sRedirect) === false)
            {
                $this->sRedirect = $this->CI->input->post('redirect');
            }

            return CI_AUTHENTICATION_INVALID_UI_INFO;
        }
        else
        {
            $sRedirect = $this->CI->input->post('redirect');
            if (empty($sRedirect) === false)
            {
                $this->sRedirect = $this->CI->input->post('redirect');
            }
            $sPassword = $this->add_salt($this->CI->input->post('password'));
            $oQuery = $this->CI->db->query("EXEC checklogin @p_username=" . $this->CI->db->escape($this->CI->input->post('username')) . ", @p_password=" . $this->CI->db->escape($sPassword));

            if ($oQuery->num_rows() == 1)
            {
                $aUserdata = $oQuery->row_array();
                //die(print_r($aUserdata));
                 $this->CI->session->set_userdata($aUserdata);
                 //die(print_r($this->CI->session->userdata('user_id')));
                 if ($this->CI->input->post('remember') == 'true')
                {
                    // todo register cookie
                }

                 return CI_AUTHENTICATION_SUCCESS;
            }
            else
            {
                return CI_AUTHENTICATION_FAILED;
            }
        }
    }

As you can see in the comments I've been printing the session data when it's just added and it works fine.

Then on the dashboard I have the following source:

Code:
function __construct()
    {
        parent::Controller();
        die($this->session->userdata('user_id'));
        if (!$this->authentication->check()) {
            redirect('logout');
        }
    }

Which calls this function:

Code:
function check($iFunctionLevel = null)
    {
        $iUserId = $this->CI->session->userdata('forename');
        die($this->CI->session->userdata('forename'));

        if (empty($iUserId) === true)
        {
            return false;
        }
        else
        {
            if ($sFunctionID === null)
            {
                return true;
            }
            else
            {
                if ($this->CI->session->userdata('access_level') >= $iFunctionLevel)
                {
                    return true;
                }
                else
                {
                    $this->CI->session->set_flashdata('message', 'Insufficient Access Rights.');
                    $this->CI->session->set_flashdata('type', 'error');
                    return false;
                }
            }
        }
    }

But as you can see from the dashboard source, the die doesn't contain anything. The session if not set and if I remove this die() the second die() in check() also returns nothing.

I've searched. I've tried. I've screamed (didn't help much). I've read. I've researched. And none of the previous have yielded any success. Does anyone have any ideas what might be going on?

FYI my browsers (both FF and IE7) are set to accept cookies (with no exceptions).

If any information is missing that you need from me, just ask.

Many thanks in advance,

Richard.


Messages In This Thread
Sessions not saving... - by El Forum - 03-12-2009, 10:12 AM
Sessions not saving... - by El Forum - 03-12-2009, 10:21 AM
Sessions not saving... - by El Forum - 03-12-2009, 10:25 AM
Sessions not saving... - by El Forum - 03-12-2009, 10:28 AM
Sessions not saving... - by El Forum - 03-12-2009, 10:35 AM
Sessions not saving... - by El Forum - 03-12-2009, 10:44 AM
Sessions not saving... - by El Forum - 03-12-2009, 10:57 AM
Sessions not saving... - by El Forum - 03-12-2009, 10:59 AM
Sessions not saving... - by El Forum - 03-12-2009, 11:08 AM
Sessions not saving... - by El Forum - 03-12-2009, 11:18 AM
Sessions not saving... - by El Forum - 03-12-2009, 11:21 AM
Sessions not saving... - by El Forum - 03-12-2009, 11:28 AM
Sessions not saving... - by El Forum - 03-12-2009, 11:45 AM
Sessions not saving... - by El Forum - 03-12-2009, 11:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB