CodeIgniter Forums
Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 (/showthread.php?tid=75042)



Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 - reesethebeast - 12-12-2019

I am using Codeigniter 3.1.11 on my localhost with XAMPP PHP version 7.3.11. I am using database sessions, not file.

I wrote some simple code to put user cart data into the session. On the initial form submission, the data is put in the session and looks good. On refresh, the session is regenerated and the prior session data is not there in the new session but is still there in an old session. Below are my config settings. I tried many combinations and cannot figure out the issue. Why does the session regenerate even when I set to FALSE?

On page refresh, I echo $this->Session->all_userdata() and I receive:

Code:
Array
(
    [__ci_last_regenerate] => 1576124405
)

Each refresh generates a new number.

The initial session data looks good, as below:

Code:
Array
(
    [__ci_last_regenerate] => 1576165611
    [CART] => Array
        (
            [0] => Array
                (
                    [product_id] => XYZ1234567
                    [qty] => 1
                )

        )

)

Config settings

Code:
$config['sess_driver']            = 'database';
$config['sess_cookie_name']        = 'ci_sessions';
$config['sess_expiration']        = 7200;
$config['sess_save_path']          = 'ci_sessions';
$config['sess_match_ip']          = FALSE;
$config['sess_time_to_update']    = 300;
$config['sess_regenerate_destroy'] = FALSE;

$config['cookie_prefix']    = 'card_';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;



RE: Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 - reesethebeast - 12-16-2019

I guess I will answer this myself then.

I got this partially working by applying a solution from another thread where the REGEX was incorrect when checking the cookie. However this only partially works or works sometimes. This logic is not always executed so I think there is another place in the standard CI session code which also needs to be changed.

\system\libraries\session\Session.php

//Line 136 changed by me on 12.15.2019 -mb
//OR ! preg_match('#\A'.$this->_sid_regexp.'\z#', $_COOKIE[$this->_config['cookie_name']])
OR ! preg_match('/^[0-9a-f]/', $_COOKIE[$this->_config['cookie_name']])


RE: Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 - InsiteFX - 12-16-2019

Why not save the users cart on there system using a secure cookie
or to the database?


RE: Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 - reesethebeast - 12-16-2019

(12-16-2019, 01:17 PM)InsiteFX Wrote: Why not save the users cart on there system using a secure cookie
or to the database?

I am using session in DB, I do not want to post to another database table as users are not logged in so I would need to determine which order belongs to which online user, which is what the session is for.


RE: Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 - steveolateru - 01-28-2020

This is usually caused by incompatibility between Codeigniter and PHP versions. For example, running Codeigniter version 3.1  on PHP 7.3.11 will result in unexpected behaviours like session regeneration.
Try upgrade to latest Codeigniter version, it should resolve the issue.


RE: Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 - garabudas - 06-19-2020

hi, i know this reply is late, I also had this same problem with shopping cart and sessions and even some of my function calls were not working.
I noticed that for every request(or function call) I make there was no cookie request, and after a lot of reading, I learned that it is usually a URL setting in our CI app.
initially my $config['base_url'] looked like this: 'https://site.domain.com'
what I did was change it to 'https://www.site.domain.com' and the cookie requests were now included in every function call and the session is behaving as it should. hope this helps


RE: Codeigniter 3.1.11 - Session regenerate and data loss PHP 7.3.11 - marcsinfo - 07-26-2021

Thanks @garabudas for this. But, it didn't work for us on CI3.1.11 & PHP 7.2.34. Any other changes were done along with this simple change of 'base_url' in config file?