April 7, 2013 asvignesh 0Comment

Session often breaks in codeigniter ??? Here is the fix !

I developed e-commerce website using php codeigniter and it is using database to store session values. But the session is lost if it has more data in it

I have spent some days checking about it and changed the third party session library , it has lots of limitations again i switched back to codeigniter default session library and trying to fix the issue finally i found out the issue in it. It was failing to unserialize the session data stored in the user_data field in ci_session table

So I have changed the field type of ‘user_data’ from ‘text’ to ‘longtext’ and now it is able to store more data in session , problem is fixed

The preferred table structure for the ci_sessions

 CREATE TABLE `ci_sessions` (
 `session_id` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT ‘0’,
 `ip_address` varchar(16) COLLATE utf8_unicode_ci NOT NULL DEFAULT ‘0’,
 `user_agent` varchar(120) COLLATE utf8_unicode_ci NOT NULL,
 `last_activity` int(10) unsigned NOT NULL DEFAULT ‘0’,
 `user_data` longtext COLLATE utf8_unicode_ci,
 PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

 

Software developer experience in building storage management and Data protection software for the Private and public cloud.

Disclaimer :

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. my thoughts and opinions change from time to time… This weblog is intended to provide a semi-permanent point in time snapshot and manifestation of the various memes running around my brain, and as such any thoughts and opinions expressed within out-of-date posts may not the same, nor even similar, to those I may hold today.

Leave a Reply

Your email address will not be published. Required fields are marked *