4

I have a problem when saving array into session data in Codeigniter.

var_dump($this->session->userdata('data')); // output is boolean false

$array = array(0 => 'abc', 1 => 'def', 2 => 'ghi');
$this->session->set_userdata(array('data' => $array, 'name' => 'my_name'));

var_dump($this->session->userdata('data')); // output is 0 => 'abc', 1 => 'def', 2 => 'ghi'

Everytime page is loaded "userdata('data')" is lost but other userdata is ok. It means only this array is lost. I'm 100% sure it can work, it worked for me before i did lot of modifications, so now i can't find solution.

Thanks.

3
  • change your session handler to database and check it, and tell me result Commented Jul 10, 2012 at 13:30
  • i don't work with database in this case Commented Jul 10, 2012 at 13:35
  • Can we see the configuration variables set in CodeIgniter for sessions? It should be in application/config/config.php Commented Jul 10, 2012 at 14:20

3 Answers 3

7

I have found what's the problem. Codeigniter has some limits in session, my array was too big. More info here

Sign up to request clarification or add additional context in comments.

Comments

0

It's seems that the cookies are disabled in your navigator.

2 Comments

it is enabled, in same session i have data i can read, for example about login. i lost only an array
@mesnicka yes u r right there r some limits for CI session & CI session does not acts like PHP $_SESSION. I also faced this problem & what I did I just set reference id in my case db row ids & then acess them but it is not what i exactly want but to move forward I used this approach :(
0

You need to use a database. The 4kb limit is a browser limit for cookie sizes. It's generally a good practice to keep cookies and session small, since every request header to an object on a server (for the same domain) will send this cookie.

Also, a good tip for CI concerning database session table's, set the type to MEMORY, so that the sessions are stored in RAM instead of disk, which makes your site quicker.

The SQL

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id)
);

CI Configuration (in application/config/config.php):

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.