Access Session data in codeigniter

 $username = $this->input->post('username');
$password = $this->input->post('password');
$result = $this->AccountModel->login($username,$password);
if($result){
foreach($result as $row){
$loggedin = array('Admin_name' => $row['username'], 'is_loggedin' => TRUE);
$this->session->set_userdata($loggedin);

How would i be able to access ['Admin_name'] and ['is_loggedin'] without having to run this code and running a foreach loop $this->session->all_userdata()

Answers


From "Retrieving Session Data" section of Session Class docs:

Any piece of information from the session array is available using the following function:

$this->session->userdata('item');

So you want:

$this->session->userdata('Admin_name');

The docs are your friend ;)


try this

 $this->session->userdata('Admin_name');
 $this->session->userdata('is_loggedin');

You can access as below:

$Admin_name = $this->session->userdata('Admin_name');

For session library, please check the CI User guide on sessions


u can access it by using this line

$this->session->userdata['Admin_name'];

it should work ..if it dosen't ..just print the session variables using any of the line below

echo '<pre>';print_r($this->session->all_userdata());exit;
echo '<pre>';var_dump($this->session->all_userdata());exit;

once u see the structure of userdata ..u can easily access any session variables in there just like any other array ..just use

$this->session->userdata['array_key'];


Need Your Help

Storing object pointers efficiently for game c++

class pointers vector

I'm making a hooked modding code for GTA San Andreas. The game has its own classes, one of them is class CPed. It handles the attributes of random pedestrians created by the game, which is huge in

SQL - How do I search for "weight" within CONTAINS?

sql vb.net contains

We have a full-text index setup to allow searching a directory for PDF files containing specified text. I've been getting notifications that's it's blowing up when people are searching for "weight ...