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

前端 未结 7 1514
误落风尘
误落风尘 2020-12-20 14:00

I created a login page with codeigniter,but i get the php message.

Message: ini_set(): A session is active. You cannot change the session module\'s ini setting

7条回答
  •  悲&欢浪女
    2020-12-20 14:22

    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

提交回复
热议问题