I had a problem where CodeIgniter sessions stored in the database were creating multiple session_id’s (each time the session library was called) for the same user.
Here is how my session configuration is defined…
$config['sess_cookie_name']Â Â Â Â Â Â = 'my-session';
$config['sess_expiration']Â Â Â Â Â Â = 60*60*2; //2 hours
$config['sess_expire_on_close']Â Â Â = TRUE;
$config['sess_encrypt_cookie']Â Â Â = FALSE;
$config['sess_use_database']Â Â Â = TRUE;
$config['sess_table_name']Â Â Â Â Â Â = 'sessions';
$config['sess_match_ip']Â Â Â Â Â Â = FALSE;
$config['sess_match_useragent']Â Â Â = TRUE;
$config['sess_time_to_update']Â Â Â = 300;
Here is the updated table structure…
CREATE TABLE IF NOT EXISTS `sessions` (
 `session_id` varchar(32) NOT NULL default '0',
 `ip_address` varchar(16) NOT NULL default '0',
 `user_agent` varchar(255) NOT NULL,
 `last_activity` int(10) unsigned NOT NULL default '0',
 `user_data` text NOT NULL,
 PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
My solution… First, I increased the user_agent field to 255 characters in length. Then, since session_id is always 32 characters in length, I reduced that from 40. If you have any other suggestions, feel free to leave a comment.
Hope this helps someone else having the same problem with CodeIgniter sessions that are being stored in the database 🙂