Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CodeIgniter Session Not Persisting

Posted on 2015-02-08
7
Medium Priority
?
638 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 84

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 84

Expert Comment

by:Dave Baldwin
ID: 40597378
I don't use Codeigniter so I'll to take your word for that.
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

670 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