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

edited June 2017 in Bug Reports
I keep getting this error when the admin is logged in, I guess this will be the case when any user is logged in.
Detailed error message:

A PHP Error was encountered

Severity: Warning

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

Filename: Session/Session.php

Line Number: 316
I guess this is a codeigniter bug which suggests adding session_start() before loading the session library $this->load->library('session');

The cms is using session library at files fuel\modules\fuel\controllers\User.php, Reset.php, Pages.php, Login.php

I tried adding the below fragment before the session load library

if(function_exists(session_status)){
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
}else{
if(session_id() == '') {
session_start();
}
}
But I keep getting -
Message:  A session had already been started - ignoring session_start()
Could you suggest a solution for this?
Thanks.

Comments

  • edited 12:52PM
    Do you have session_start somewhere else in your codebase?
  • edited 12:52PM
    No, I have not used session_start anywhere.. Why is the forum panel not accessible via phone!
  • edited 12:52PM
    Hi Admin,

    Any luck here..
  • edited 12:52PM
    I'm unfortunately not able to replicate this issue locally. Is this happening to you on a fresh install of FUEL?
  • edited 12:52PM
    I don't know, what qualifies for fresh install. Initially on the fresh install there is only one home page. I logged in to admin panel, but I guess there is not much happening on a fresh install, so there is no session related issue.
    The issues started showing up once I have added modules - custom models for data. Then the home page started showing session error that I have mentioned above.
  • edited 12:52PM
    Were you able to identify what custom modules seemed to be triggering the error?
  • edited 12:52PM
    Hi Admin,

    Extremely sorry for the delayed response, as I had some deployments lined up!

    I tried commenting each one of the modules but still not able to figure out what was causing the session error to popup.

    I tried to work-around the issue by creating a function which check whether the session is already set!

    //custom function to check if the session error is resolved
    function is_session_started()
    {
    if ( php_sapi_name() !== 'cli' ) {
    if ( version_compare(phpversion(), '5.4.0', '>=') ) {
    return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
    } else {
    return session_id() === '' ? FALSE : TRUE;
    }
    }
    return FALSE;
    }
    I added the above function in
    fuel/codeigniter/libraries/Session/Session.php end of file in the CI_Session class
    Also introduced the check on line 143
    if ( $this->is_session_started() === FALSE ) session_start();
    In the same file at line 316, I resolved or rather suppressed the error
    ini_set(): A session is active. You cannot change the session module's ini settings at this time
    by commenting out line 316
    //ini_set('session.use_trans_sid', 0);
    I am not sure if the above commented line will have any adverse effects! I would like to know if I should go ahead this way. The above mentioned actions sorted the session related issues.
  • TomTom
    edited March 2018
    I recreated above (similar) error by creating some entries in aggresive_redirects config array, when trying to remove possible duplicate content of pages (when google is performing page indexing).
    Shows only with logged user (admin, and other ones created), in development mode.

    Steps performed:

    - installed fresh fuel-cms v1.4.2
    - installed mysql database, created user, installed sql schema
    - modified fuel/application/config/database.php for sql access
    - modified fuel/application/config/MY_fuel.php :
    $config['admin_enabled'] = TRUE;
    $config['fuel_mode'] = 'auto';
    $config['language_mode'] = 'segment';

    - added to fuel/application/config/MY_fuel.php language configuration setting:
    $config['settings'] = array();
    $config['settings']['languages'] = array(
    'type' => 'keyval',
    'fields' => array(
    'key' => array('ignore_representative' => TRUE),
    'label' => array('ignore_representative' => TRUE),
    ),
    'class' => 'repeatable',
    'repeatable' => TRUE,
    'ignore_representative' => TRUE
    );

    - logged in fuel cms
    - set fuel language settings:
    pl:Polski
    en:English
    - created 'home' page, with different page titles to see the difference between language versions
    - added agressive redirects:
    $config['case_sensitive'] = FALSE;
    $config['aggressive_redirects'] = array(
    'pl' => '/',
    'home' => '/',
    'pl/home' => '/',
    'en/home' => 'en',
    );

    Redirects works ok, but page spits warnings, also fuel inline control box doesn't show buttons and laguage select.

    ---

    PHP Error was encountered

    Severity: Warning

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

    Filename: Session/Session.php

    Line Number: 314

    Backtrace:

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 791
    Function: __construct

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 684
    Function: _ci_init_library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 538
    Function: _ci_load_stock_library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 592
    Function: _ci_load_library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 198
    Function: _ci_load_library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_auth.php
    Line: 137
    Function: library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_auth.php
    Line: 473
    Function: valid_user

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_auth.php
    Line: 324
    Function: is_super_admin

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1292
    Function: has_permission

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1402
    Function: render_marker

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1388
    Function: preg_replace_callback

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1193
    Function: render_all_markers

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\controllers\Page_router.php
    Line: 137
    Function: fuelify

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\controllers\Page_router.php
    Line: 84
    Function: _remap_cms

    File: C:\xampp\htdocs\fuel-test\index.php
    Line: 364
    Function: require_once
    A PHP Error was encountered

    Severity: Notice

    Message: A session had already been started - ignoring session_start()

    Filename: Session/Session.php

    Line Number: 143

    Backtrace:

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 791
    Function: __construct

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 684
    Function: _ci_init_library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 538
    Function: _ci_load_stock_library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 592
    Function: _ci_load_library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\core\Loader.php
    Line: 198
    Function: _ci_load_library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_auth.php
    Line: 137
    Function: library

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_auth.php
    Line: 473
    Function: valid_user

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_auth.php
    Line: 324
    Function: is_super_admin

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1292
    Function: has_permission

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1402
    Function: render_marker

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1388
    Function: preg_replace_callback

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1193
    Function: render_all_markers

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\controllers\Page_router.php
    Line: 137
    Function: fuelify

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\controllers\Page_router.php
    Line: 84
    Function: _remap_cms

    File: C:\xampp\htdocs\fuel-test\index.php
    Line: 364
    Function: require_once
    A PHP Error was encountered

    Severity: Warning

    Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\fuel-test\fuel\codeigniter\core\Exceptions.php:271)

    Filename: core/Input.php

    Line Number: 408

    Backtrace:

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_language.php
    Line: 395
    Function: set_cookie

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_language.php
    Line: 163
    Function: set_cookie

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_language.php
    Line: 344
    Function: set_selected

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_admin.php
    Line: 1401
    Function: detect

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\libraries\Fuel_pages.php
    Line: 1212
    Function: toolbar

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\controllers\Page_router.php
    Line: 137
    Function: fuelify

    File: C:\xampp\htdocs\fuel-test\fuel\modules\fuel\controllers\Page_router.php
    Line: 84
    Function: _remap_cms

    File: C:\xampp\htdocs\fuel-test\index.php
    Line: 364
    Function: require_once

    ---

    Can someone share a suggestion for better redirecting of fuel created pages ?
    For now, i need to redirect these 4 unnecesary links (routed by fuel-cms) to '/' (domain home page) and '/en' for english version of page.
    But now I realized that for every polish page 'something' i will be having it also under 'pl/something' link, uhhhh....
  • edited 12:52PM
    Thanks for the recreation steps. The issue had to do with the Session library being called after the Fuel_redirects already called session_start() (without using the library). The reason it is used in Fuel_redirects is to prevent runaway redirects and a session variable is used to keep count of how many times it was redirected.
  • TomTom
    edited March 2018
    I see.

    Anyways I fixed my needs with .htaccess entries :

    # default language redirects
    RewriteRule ^pl$ $1 [L,R=301]
    RewriteRule ^pl/(.*)? $1 [L,R=301]
    RewriteRule ^pl/home/(.*)? $1 [L,R=301]
    RewriteRule ^home/? $1 [L,R=301]
    RewriteRule ^en/home? en/ [L,R=301]

    # Allow asset folders through ...

    It can be usefull for someone who needs multi-language pages in Fuel-CMS and it should be be now properly indexed by search engines (fixes duplicate website content issue). (I hope :)

    One need just put default language segment instead of 'pl' and add other(s) used language segment(s) instead of 'en' (each {ln}/home entry for each used language except default one).
Sign In or Register to comment.