CodeIgniter Session Not Persisting

I am having a problem where I am able to successfully set (and retrieve) session data in my login controller, but when I forward a user to on to the destination page, the session data that I set is not being found. I have researched and found others saying that playing around with the cookie domain in the config file has helped them, but it doesn't seem to do anything for my problem. If it helps for troubleshooting, I'm using an HTTPS site with the cookie_secure set to TRUE and have tried both a blank domain and "" and it doesn't seem to help. sess_encrypt_cookie is TRUE and sess_use_database if FALSE. I have verified that the system clock is set correctly as well.

Why isn't my session persisting?!
Who is Participating?
dale_abramsConnect With a Mentor Author Commented:
After banging my head against a wall for a week now, I have figured out my issue. All of the CI session configuration and usage was correct for the record. What was happening was that the cookie size was going past the (seemingly arbitrary) browser 4kb limit and the cookie was getting wiped out by the browser before the next page load. To fix this, I moved my session to be stored in the database. After doing this, I found a further issue with the recommended ci_sessions table config that CI provides in the documentation. They give a user agent field with a length of 120, which also caused problems and in turn created a new session every time a page (or AJAX request) loaded. So, to try and help the next guy with this same issue, here is the ci_sessions table creation SQL that will work if you're finding that your session data is too large...
DROP TABLE IF EXISTS `ci_sessions`;
	session_id varchar(100) DEFAULT '0' NOT NULL,
	ip_address varchar(100) DEFAULT '0' NOT NULL,
	user_agent varchar(300) 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`)

Open in new window

Dave BaldwinFixer of ProblemsCommented:
Do you have 'session_start();' at the top of every page?
dale_abramsAuthor Commented:
Hi Dave. I'm using CodeIgniter. It has a build in mechanism for handling sessions. I did forget to include that I have $autoload['libraries'] = array('session'); set in my autoload file. That is the equivalent of having session_start() at the top of every page.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Dave BaldwinFixer of ProblemsCommented:
I don't use Codeigniter so I'll to take your word for that.
Marco GasiFreelancerCommented:
Please, what is the code you're using to access session data? And have you tried to use var damp to check the content of the session?
Loganathan NatarajanLAMP DeveloperCommented:
Just verify whether you have set the session value correctly as per CI syntax and try to print on the same page to check.
Then on the destination page enable session library and print it. It should work.

More details here,  CI Sesssion
dale_abramsAuthor Commented:
Other solutions were not helpful in pointing me in the right direction to fix the issue I was encountering. So, I accepted my own solution in the hopes that it will be found by someone else with the same issue and save them the headache.
All Courses

From novice to tech pro — start learning today.