Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time

You don't need this line in admin.php

session_start(); //need to call PHP's session object to access it though it

When you load the session library, its constructor does this for you.


The message means that you have started a session with session_start() in which further down in the code you are using ini_set() to manipulate the session module. If you are manipulating the session module, it should be done before a session is started and active.


Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time

I had same error message sometime ago , By default Code-igniter will write to file (C:\xampp\tmp) in my case. But I want it to write to database instead.

In your autoloader you might have had something like this:

//:::::$autoload['libraries'] = array();
//'session', this mean start session ini_set()
$autoload['libraries'] = array('session', 'database');

By default setting in the config/config.php session configurartion look like this:

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

The documentation stated that to use database instead of file you should first create a table in application database.

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`)
);

Go back to the config/config.php and change $config['sess_driver'] = 'files'; to $config['sess_driver'] = 'database';

Like so I thought everything should be fine but I got the error Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time

My Solution was to first run the session_destroy();

Then change session name and table name

My config look like this :

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'newname_session';
$config['sess_expiration'] = 72000;
$config['sess_save_path'] ='newname_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

Save everything and after refresh the page all cleared, no error message showing