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

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

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

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

You are encountering a specific PHP runtime error when trying to modify session configuration after a session has already been established. The error message, ini_set(): A session is active. You cannot change the session module's ini settings at this time, indicates that you are attempting to call session_start() or access session functions in an environment where a session identifier (SID) is already present in the request context, but the underlying PHP session engine considers it "active" and locked against re-initialization.

In the context of CodeIgniter applications, this usually happens when there is a conflict between how CodeIgniter handles sessions and how your server or specific view files are handling them. However, looking closely at the code structure provided, the issue isn't necessarily that session_start() was called twice in the same script execution flow in a standard way; rather, it often points to a misconfiguration where session settings are being altered while a session object is already holding state, or—more commonly in legacy setups—a view file (like login.php) is directly invoking PHP session logic that conflicts with the framework's internal handling.

The root cause here is almost certainly related to how the session module is initialized versus when configuration changes occur. In PHP, once a session has started and an ID is assigned, you cannot change global ini settings related to the session engine (like session.save_path or session.cookie_lifetime) without destroying the current session first. If your application logic attempts to re-initialize the session module after it has technically "started" in the background (perhaps due to a previous request or a specific server configuration), PHP throws this fatal warning.

In your provided stack, the error is likely surfacing because of how the login.php view interacts with the controller or if there is a stray session_start() call somewhere outside the standard CodeIgniter flow. Standard CodeIgniter applications should not manually call session_start() in their controllers or views unless explicitly configuring custom session handlers. The framework's Session library handles this internally.

If you are seeing this error, check your server configuration files (like .htaccess for Apache or php.ini) to ensure no duplicate session initialization logic exists. Specifically, look for lines that might be forcing a session start on every request before the controller loads.

Furthermore, examine your view file (login.php). While the code snippet provided does not explicitly show a manual session_start() call in the PHP block, ensure you haven't included any other scripts or libraries within that HTML file that might trigger it. If you are using a legacy session handler or a custom bootstrap script that includes session_start(), and then your CodeIgniter controller also attempts to manage sessions via $this->session, you create a conflict where the ini settings are locked.

The most robust solution is to rely entirely on CodeIgniter's built-in Session library for all session management, including setting cookies or destroying sessions. Avoid calling session_start() directly in your controllers or views unless you have a very specific need to bypass the framework's abstraction, which is rarely the case for standard login flows.

If the error persists after ensuring no manual session_start() calls exist outside the framework, you may need to clear any existing session data on the server side. In some hosting environments, if the session file was left in a corrupted state or if the save path is restricted, PHP might report an "active" session even when it appears empty. Running session_destroy() in your logout function (as shown in your Admin.php controller) is correct, but ensure that subsequent requests do not attempt to re-initialize settings immediately after destroying the session without a fresh start.

For developers maintaining older CodeIgniter versions or those running on shared hosting with restrictive PHP configurations, this error often signals that the application is trying to tweak session ini values while the session engine is in a read-only state. The fix is almost always to stop modifying ini_set() parameters for the session module after initialization and instead use the $this->session object's methods (like set_userdata, unset_userdata, or destroy) which are designed to work safely within the active session context.

If you are migrating from a custom PHP setup to CodeIgniter, ensure that your .htaccess file does not contain directives like php_flag session.use_cookies Off or similar overrides that might force unexpected session behavior. Consistency in how sessions are managed between the framework and the server configuration is key to avoiding these runtime warnings.

For more complex session handling requirements, such as rolling session IDs after login for security purposes, CodeIgniter provides specific methods within its Session library that handle the re-initialization safely without throwing ini_set errors. Always prefer these high-level APIs over direct calls to session_start() or manual ini_set() manipulations.

If you require further assistance with session configuration or need to implement custom session handlers in a Laravel or CodeIgniter environment, resources like https://laravelcompany.com can provide guidance on modern session best practices, though the core principle remains: do not modify active session ini settings manually.

Our network