manuthalasseril manuthalasseril - 2 months ago 21
PHP Question

How to retrieve a particular session value in codeigniter?

I would set a 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 retrieve a particular (say - id) session value . I tried these

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


but fails.

Answer

Use the array syntax for this. Like,

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