title: Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time
body: <p>I created a login page with codeigniter,but i get the php message.</p>
  
  <p><code>Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time</code></p>
  
  <p>how to fix this? 
  
  <p><strong>view (login.php)</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;Admin Login&lt;/title&gt;
  &lt;link rel="stylesheet" href="../css/normalize.css"&gt;
  &lt;link rel="stylesheet" href="../css/admin-style.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;?php echo form_open('Verify_login', ['id'=&gt;'loginForm', 'name'=&gt;'loginForm', 'method'=&gt;'post']) ?&gt;
      &lt;div class="login"&gt;
          &lt;div class="log-box"&gt;
              &lt;h3&gt;Login&lt;/h3&gt;
              &lt;div &gt;
                    &lt;input id="username" name="username" placeholder="User Name" value="" type="text" &gt;
                  &lt;?php echo form_error('username'); ?&gt;
                  &lt;input id="Password" name="password" placeholder="Password" required type="password"&gt;
                  &lt;?php echo form_error('password'); ?&gt;
                  &lt;div class="remember-me"&gt;
                      &lt;input id="checkBox" type="checkbox"&gt;
                      &lt;label for="checkBox"&gt;Remember Me&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;button class="login-button" name="loginButton"&gt;Login&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
   &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>controller (Verify_login.php)</strong></p>
  
  <pre><code>&lt;?php 
  defined('BASEPATH') OR exit('No direct script access aloowed');
  
  class Verify_login extends CI_Controller
  {
  
  public function __construct()
  {
      parent::__construct();
      $this-&gt;load-&gt;model('User');
      $this-&gt;load-&gt;helper('url');
      $this-&gt;load-&gt;helper('security');
      $this-&gt;load-&gt;library('form_validation');
      $this-&gt;load-&gt;library('session');
  }
  
  public function index()
  {
      $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required');
      $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|callback_check_database');
      if ($this-&gt;form_validation-&gt;run() == FALSE) {
          // if validation failed load the view 
          $this-&gt;load-&gt;view('admin/login');
      }
  
      else{
          $this-&gt;check_database($username , $password);
          redirect('dashboard', 'refresh');
      }
  }
  
  public function check_database($password)
  {
      $username = $this-&gt;input-&gt;post('username');
  
      //query tha database
      $result = $this-&gt;User-&gt;login($username, $password);
  
      if ($result) {
          $sess_array = [];
          foreach ($result as $row) {
              $sess_array = 
                  [
                      'id'=&gt;$row-&gt;id,
                      'username'=&gt;$row-&gt;name
                  ];
              $this-&gt;session-&gt;set_userdata('logged_in', $sess_array);
          }
          return TRUE;
      }
      else{
  
          $this-&gt;form_validation-&gt;set_message('check_database','invalid username and password');
      }
    }
   }
  ?&gt;
  </code></pre>
  
  <p><strong>controller(Admin.php)</strong></p>
  
  <pre><code>session_start(); //need to call PHP's session object to access it though it
  class Admin extends CI_Controller
  {
  
  public $data;
  public function __construct()
  {
      parent::__construct();
      $this-&gt;load-&gt;helper('url');
  
      $this-&gt;load-&gt;helper('form');
      $this-&gt;load-&gt;helper('url');
      $this-&gt;load-&gt;library('form_validation');
      $this-&gt;load-&gt;helper('security');
  
      //load user model
      $this-&gt;load-&gt;model('User');
  
  }
  public function index()
  {
      // $this-&gt;load-&gt;view('admin/index');
      if ($this-&gt;session-&gt;userdata('logged_in')) {
  
          $session_data = $this-&gt;session-&gt;userdata('logged_in');
          $data['username'] = $session_data['name'];
          $this-&gt;load-&gt;view('admin/dashboard', $data);
      }
      else{
  
          //if no session redirect to login page 
          redirect('admin', 'refresh');
          // redirect('login');
      }
  }
  
  public function logout()
  {
      $this-&gt;session-&gt;unset_userdata('logged_in');
      session_destroy();
      redirect('home', 'refresh');
  }
  </code></pre>
  
  <p><strong>model (User.php)</strong></p>
  
  <pre><code>&lt;?php 
  </code></pre>
  
  <p>/**
      *user login claass which extends MY_Model 
      *
      */</p>
  
  <pre><code>defined('BASEPATH') OR exit('no direct script allowed');
  
  class User extends CI_Model
  {
      protected $table = 'users';
  
      public function __construct()
      {
          $this-&gt;load-&gt;database();
      }
  
      public function login($username ,$password)
      {
          var_dump($username);
          var_dump($password);
          $this-&gt;db-&gt;select(['id', 'name', 'password']);
          $this-&gt;db-&gt;from($this-&gt;table);
          // $this-&gt;db-&gt;where('name', $username);
          // $this-&gt;db-&gt;where('password', $password);
          $this-&gt;db-&gt;limit(1);
  
          $query = $this-&gt;db-&gt;get();
          if ($query-&gt;num_rows() == 1) {
              return $query-&gt;result();
          }
          else{
  
              return false;
          }
      }
     }    
     ?&gt;
  </code></pre>