1
votes

I have checked the result but unable to solve my error.
I have simply used session_start and it gives this warning message.

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

Below is my code -

$sess_array = array(
                      'id' => $row->empid,
                      'username' => $row->emp_name,
                      'loggedIn' => '1',
                      'usertype' => $usertype
                  );  
$this->session->set_userdata('logged_in', $sess_array); // store session    

Dashboard.php page-

session_start();   

error_reporting(E_ALL & ~E_NOTICE);    

//error_reporting(0);   

if (!defined('BASEPATH'))    

 exit('No direct script access allowed');    




class Dashboard extends CI_Controller
{

public function __construct()
{
    parent::__construct();

}

public function index()
{

    if ($this->session->userdata('logged_in'))
    {
        $EmpName = $this->session->userdata['logged_in']['username'];
        $Emp_id = $this->session->userdata['logged_in']['id'];  
  }  
}  

Although the same question has asked but i didnt get the proper solution for this question. Please anyone solve that query.

3
remove session_start(); from dashboard.php. Codeignitor itself started session when project initiated through URL. (through configuration files)Anant Kumar Singh
then it passes the if condition where session is checking and it goes into else partManeesh Sharma
There is no else part in that codebrombeer
Sorry i forgot to mention else part. but there is also a else part in this code.Maneesh Sharma

3 Answers

1
votes

This is really working for me, basically you check for session first then if it is not initialized then you call ini_set and others and then call the session_start()

if (!isset($_SESSION)) {

// server should keep session data for AT LEAST 24 hour
ini_set('session.gc_maxlifetime', 60 * 60 * 24);

// each client should remember their session id for EXACTLY 24 hour
session_set_cookie_params(60 * 60 * 24);
session_start();
}

so you do start your session after calling ini_set and session_set_cookie_params etc

0
votes

Instead of using session_start(); you should load the session library codeigniter has provided for you in the application/config/autoload.php file go the line where:

$autoload['libraries'] = array('session');

Or if you want to load the library from only your Dashboard controller, you can load it via $this->load->library('session');, where you can put it in the constructor to be able to work with it inside the hole controller, or add it in a specific method.

0
votes

I just updated my session redis driver file: "system/libraries/Session/drivers/Session_redis_driver.php" by codeigniter 3.11.1 one: new driver file and this error has disappeared

in application/config/config.php file please put next:

$config['sess_driver'] = 'redis';
$config['sess_save_path'] = 'your-redis-instance:port'
$config['sess_match_ip'] = FALSE;
$config['sess_regenerate_destroy'] = FALSE;

it works so far.