Like I said in title. I have problem in CodeIgniter (version 3.1.6 and 3.1.7). In same method - it's working, but went I call userdata in other method, or other controller, or model I see only this:
print_r($this->session->userdata('user_session'));
Let's look at simple example (remember, it's not my full code!): So, controller Sessiontest.php:
class Sessiontest extends CI_Controller{
public function __construct()
{
parent::__construct();
//session library loaded by autoload.php
}
public function firstStep()
{
echo 'set userdata';
$data = array(
'example1' => '123',
'example2' => 321
);
$this->session->set_userdata('user_session', $data);
print_r($this->session->userdata('user_session'));
}
public function secondStep()
{
echo 'get userdata ';
print_r($this->session->userdata('user_session'));
}
}
And in browser: .../sessiontest/firststep:
set userdataArray ( [example1] => 123 [example2] => 321 )
.../sessiontest/secondstep:
get userdata
Same effect when I use files driver and database driver. Any help will be appreciated. I don't hide that I'm beginner, but I can't resolve this without any kind of help.
//Edit #1: Additional: Tested in Opera and in Chrome.
//Edit #2: Every refresh creates next new session file when I'm using files driver, and next new row in database, when I'm using database driver.
//Edit #3: Changes suggested in the answers.
$this->session->set_userdata('namehere', $data);
and when getting session value$this->session->userdata('namehere');
– Ankit Singh