Saving an array for a session in Codeigniter

I have a problem while saving an array in 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' 

Any page "userdata ('data')" is loaded is lost, but other user data is in order. This means that only this array is lost. I am 100% sure that it can work, it worked for me before I made many changes, so now I can not find a solution.

Thanks.

+4
source share
3 answers

I found that problem. Codeigniter has some session restrictions, my array was too large. More here

+7
source

Cookies seem to be disabled in your browser.

0
source

You need to use a database. The 4kb limit is a browser limit on the size of cookies. It is generally good practice to save cookies and session, as each request header for an object on the server (for the same domain) will send this cookie.

Also, good advice for CI regarding a database session table, set the type to MEMORY so that sessions are stored in RAM instead of disk, which makes your site faster.

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 /config/config.php application):

 $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; 
0
source

All Articles