Jan 10, 2016

How to extend the limitation of session->userdata value in codeignator

I have faced the issues of session user data in codeignator. It consider default storing text value limit as 8000 to 9000 characters.

I was working with array of session where array of session will not store more then 8,9 values in session.

I did number of R&D for extend the storing value in session and also tried with destroying the user session unfortunately I will not success then I get one solution as below.

I checked config file where I got one option as   $config['sess_use_database'] = FALSE

Once enabled, the Session class will store session data in the DB.

$config['sess_use_database'] = TRUE

Note: By default the table is called ci_sessions, but you can name it anything you want as long as you update the application/config/config.php file so that it contains the name you have chosen. Once you have created your database table you can enable the database option in your config.php file as follows:

Make sure you've specified the table name in your config file as well:
$config['sess_table_name'] = 'ci_sessions';
CREATE TABLE IF NOT EXISTS  `ci_sessions` (
 session_id varchar(40) DEFAULT '0' NOT NULL,
 ip_address varchar(45) DEFAULT '0' NOT NULL,
 user_agent varchar(120) NOT NULL,
 last_activity int(10) unsigned DEFAULT 0 NOT NULL,
 user_data text NOT NULL,
 PRIMARY KEY (session_id),
 KEY `last_activity_idx` (`last_activity`)
);
Note: The Session class has built-in garbage collection which clears out expired sessions so you do not need to write your own routine to do it.

Its some tricky solution and help to someone.

No comments:

Post a Comment