Solved

CodeIgniter Session Not Persisting

Posted on 2015-02-08
7
520 Views
Last Modified: 2015-02-16
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 ".mydomain.com" 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?!
0
Comment
Question by:dale_abrams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40597261
Do you have 'session_start();' at the top of every page?   http://php.net/manual/en/function.session-start.php
0
 
LVL 1

Author Comment

by:dale_abrams
ID: 40597268
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.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40597378
I don't use Codeigniter so I'll to take your word for that.
0
Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40597752
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?
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 40600210
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
0
 
LVL 1

Accepted Solution

by:
dale_abrams earned 0 total points
ID: 40604347
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`;
CREATE TABLE IF NOT 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

0
 
LVL 1

Author Closing Comment

by:dale_abrams
ID: 40611863
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.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question