8

I have an application built with Codeigniter 3 HMVC.The application was working fine on PHP 5.6 version, But after upgrading my PHP version to 7.1.4 I was not able to log in into my application. After a complete checkup I found that session is not setting at all.

I role back to PHP 5.6 and session was working fine again while switching to PHP 7.1.4 bring the "session not working" issue back.

I tried altering some config value like cookie prefix and cookie save name etc, nothing seems to fix it.

Can anyone please help.

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
A1ft
  • 307
  • 1
  • 4
  • 11
  • 1
    Please, read [How to Ask Question](http://stackoverflow.com/help/how-to-ask) and [provide an MCVE : Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). **This is necessary to reproduce your issue** and this is the most useful way for you to learn how to find and fix the problem yourself. – gp_sflover May 01 '17 at 12:23
  • 2
    The question is not about my personal code... it's about a open source framework. Do you want me to paste the whole code of codeigniter 3 here. Anyone who knows codeigniter already have the code. – A1ft May 01 '17 at 12:25
  • It's not a basic level issue like I forgot to auto-load or manually load the session library, this is probably a bug in CI 3. – A1ft May 01 '17 at 12:28
  • 1
    How do you know it's not in the application code the source of the problem? – gp_sflover May 01 '17 at 12:29
  • I mean: there are changes in php7 that involves the session system management in CI3? – gp_sflover May 01 '17 at 12:31
  • Because : >> sudo a2dismod php5.6 >> sudo a2enmod php7.1 >> sudo service apache2 restart makes the session not working where >> sudo a2dismod php7.1 >> sudo a2enmod php5.6 >> sudo service apache2 restart makes the session working fine without changing a single character. Hope you got it. – A1ft May 01 '17 at 12:32
  • So in a fresh install of CI3 with php7.1 happens the same problem? – gp_sflover May 01 '17 at 12:34
  • yes @gp_sflover it might happen as CI3 was for PHP 5.6 + but PHP 7 has a lot of change in functions ... and I'm also focused on find that answer. What should be the change in session library. – A1ft May 01 '17 at 12:35
  • 2
    That's the point "_it might happen_". You should test this yourself and then, when you are sure it not depends by your app, come here with a question (_and more useful info_). Even though I think it's better to ask directly to the project maintainer. – gp_sflover May 01 '17 at 12:39
  • I got my sessions working again by rolling PHP back to 7.0 – Brendan J Nov 16 '17 at 19:52

2 Answers2

16

I found that the issue is with some earlier version of Codeigniter 3 and this is a bug already reported in their website.The underlying session bug has been fixed on:

  • 3.1.2
  • 3.1.3
  • 3.1.4

So in the latest version of Codeigniter 3 this issue doesn't happen.

Solutions:

If you are already in a faulty version codeigniter consider replacing system folder with latest version's one. Version 3.1.6 at the time writing this.

Community
  • 1
  • 1
A1ft
  • 307
  • 1
  • 4
  • 11
0

In codeigniter 3.1.9 and PHP 7.2 on XAMPP(windows), I checked my application/config/config.php and saw the sess_driver was database:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = '165_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = "ci_sessions";

So I created the database ci_sessions with:

CREATE TABLE IF NOT EXISTS `ci_sessions` (
        `id` varchar(128) NOT NULL,
        `ip_address` varchar(45) NOT NULL,
        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
        `data` blob NOT NULL,
        KEY `ci_sessions_timestamp` (`timestamp`)
);

And it worked.

shillary
  • 19
  • 1