Jump to content

Session variables return a NULL value


Recommended Posts

I'm trying to store my database values in a session so that whenever user logs in I can access those session variables to get their name, id, etc. To achieve this I'm using the following code:

Controller Class(login):

$newdata = array(
                       'clientsessid'  => $clientdata->clients_id,
                       'clientsessuserid'  => $clientdata->id,
                       'clientsesskey'  => $clientdata->client_key,
                       'clientsesusername' => $clientdata->username, 
                       'clientsessemail' => $clientdata->email,
                       'client_loginid' => $loginid,
                       'client_logged_in' => TRUE

Model class:

function get_row_cond($cond)
        $query = $this->db->get($this->table_name);
        return $query->row();

View class(dashboard):

<?php var_dump( $this->session->userdata('clientsesusername')) ?>

But doing so returns a NULL value after the user has logged in. And I've checked the database and the username for the particular person is filled.

Link to comment
Share on other sites

You do realize that a session only last as long as the current lasts?  That means when the user logs in (again?) he is beginning a new session so whatever was saved is no longer available.  If you are looking to save a small piece of data or two, perhaps a cookie would be more useful, or a simple file that you first write out somewhere and then read back in when the user logs in again.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.