Session Lost for CI 3.1.13 on Page Refresh
Author: mertdoganCreated Nov 13, 2023Updated Oct 8, 2025
Discussed in https://github.com/bcit-ci/CodeIgniter/discussions/6247
Originally posted by mertdogan November 14, 2023 Hi. I started a new CI project with CI 3.1.13.
When i refresh page everything on session lost (still on database table) and new session created.
I replaced my new system/library/session folder with CI 3.1.11 (ini_set('session.id', $params['cookie_name']); tricked) and everything works without problem and session not lost.
my simple code at controller is:
public function test(){
$this->load->library('session');
var_dump(isset($_SESSION['x'])?$_SESSION['x']:null);
$_SESSION['x']='123';
var_dump($_SESSION['x']);
}when i refresh page for CI3.1.13 than NULL 123 occurs but when i load with CI3.1.11 123 123 occurs on second page load.
I test everything on stackoverflow but can't solve problem.
my php version is 7.1.19 on IIS and using database driver for session. This is my config setting:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ODEME_PORTAL_COOKIE';
$config['sess_samesite'] = 'None';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'CI_SESSIONS';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
| 'cookie_samesite' = Cookie's samesite attribute (Lax, Strict or None)
|
| Note: These settings (with the exception of 'cookie_prefix' and
| 'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
$config['cookie_samesite'] = 'None';
Source: bcit-ci/CodeIgniter