KSI Posted November 3, 2021 Share Posted November 3, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/314160-session-variables-return-a-null-value/ Share on other sites More sharing options...
gw1500se Posted November 3, 2021 Share Posted November 3, 2021 Where do you issue the session_start()? Quote Link to comment https://forums.phpfreaks.com/topic/314160-session-variables-return-a-null-value/#findComment-1591696 Share on other sites More sharing options...
ginerjm Posted November 3, 2021 Share Posted November 3, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/314160-session-variables-return-a-null-value/#findComment-1591700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.