Fix - CodeIgniter session not set with PHP 7.x


Today I had to do some updates to an old web app I made with CodeIgniter. The original app was made around 5 years back and there has been no changes to it until this one. All this time it was living in one of my old web servers with PHP 5.6 and had no issues at all. However, when I tried to setup this in my local machine (inside Vagrant, with PHP 7.x), I found some issues with the sessions. I noticed the sessions are not getting persisted between the redirects. 

 

After some research, I found out that the issue was actually with the PHP version. Luckily, I didn't have to change it to an old PHP version. There was an easy fix (somewhat surprising), and I got it working in no time. 

 

If you ever face this issue, all you got to do is: in your CI folder, open the CI/system/libraries/Session/Session.php file and look for a line which says:

 

ini_set('session.name', $params['cookie_name']);

and change it to

 

ini_set('session.id', $params['cookie_name']);

 

and that's it. Your app should start working fine :)

0 comments :

Post a Comment