How to get a specific session value in the encoder?

I would set the session value in codeigniter

$sess_array = array( 'id' => $row->Login_Id, 'username' => $row->Login_Name, 'postid'=> $row->Fk_Post_Id, ); $CI->session->set_userdata('logged_in', $sess_array); 

Then how to get a specific session value (say-id). I tried these

 $createdby=$this->session->userdata('id'); $createdby=$this->session->userdata($logged_in['id']); 

but not executed.

+4
source share
7 answers

Use array syntax for this. How,

 $this->session->userdata['logged_in']['id']; 
+9
source

set it like this:

 $sess_array = array( 'id' => $row->Login_Id, 'username' => $row->Login_Name, 'postid' => $row->Fk_Post_Id, ); $CI->session->set_userdata($sess_array); 

Receive

 $createdby = $this->session->userdata('id'); 
+4
source
 $createdby = $this->session->userdata(logged_in['id']); 

or

 $createdby = echo $_SESSION[logged_in['id']]; 
+3
source
 $sess_array = array( 'id' => $row->Login_Id, 'username' => $row->Login_Name, 'postid'=> $row->Fk_Post_Id, ); $CI->session->set_userdata('logged_in', $sess_array); 

then

 $logged_in = $this->session->userdata('logged_in'); $createdby = $logged_in['id']; 
+3
source
 Session write process. session content could be dynamic value $logged_in = [ 'id'=> 1, 'name'=> 'test' ]; Particular Session retrieve process. $this->session->userdata['logged_in']['id']; 
+3
source
 $pdata = array( 'id' => $row->Login_Id, 'username' => $row->Login_Name, ); // pass ur data in the array $this->session->set_userdata('session_data', $pdata); //Sets the session $pdata = $this->session->userdata('session_data'); //Retrive ur session $pdata['id'] will give u the corresponding id 
+2
source

In the new version, you can simply use

 $this->session->username $this->session->id $this->session->postid 
+1
source

All Articles