Jump to content

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):

$this->load->view('crm/login/index',$main);
$clientdata=$this->login_model->get_row_cond($cond); 
$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
                );
                $this->session->set_userdata($newdata); 
                redirect('dashboard');

Model class:

function get_row_cond($cond)
    {
        $this->db->where($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
https://forums.phpfreaks.com/topic/314160-session-variables-return-a-null-value/
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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.