Php session is broken when at two sites on the same apache server

1

I have two sites that perform user authentication and soon after creating a session for it, both sites access the same database and therefore the user structure returned by the statement:

$usuario = $this->db->get('usuarios').result();

has the same fields, the session is created like this:

$this->session->set_userdata(array('logged' => true, 'usuario' => $usuario[0]));

All pages of both sites redirect the user to the login screen if the logged field is not set to true in the session, the sites work normally (I can even open multiple tabs for the same site), however , if I authenticate to one of them and try to access any page from the other, the created sessions are destroyed (on both sites if they exist). I'm using:

  

codeigniter 2.2.1, PHP / 5.4.19, Apache / 2.4.4

.

I really have no idea why.

    
asked by anonymous 01.11.2016 / 17:56

1 answer

2

Place the session path for each site (whereas there are two installations of Codeigniter).

Inside the config.php file in application / config look for the line:

$config['cookie_path'] = '/';

And put the path of each site in each config:

$config1.php
$config['cookie_path'] = '/site1';

$config2.php
$config['cookie_path'] = '/site2';
    
01.11.2016 / 18:02