php session is broken when soon on two sites on the same apache server

Asked

Viewed 88 times

1

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

$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 the two sites redirect the user to the login screen if the field logged is not set as true in the session, the sites work normally (I can even open several tabs for the same site), however, if I authenticate on one of them and try to access any page of 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 that.

  • This is probably a Codeigniter standard, when it detects two equal sessions on the same client and domain it closes the session. You could just change the name of those variables that I think would work.

1 answer

2


Places the session path for each site(Whereas there are two Codeigniter installments).

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';
  • worked, da to have an idea of why but can you explain why this? thanks!

  • 1

    The session works on the server and the cookie on the client side, but to identify which site that session belongs to the server checks the information that is contained in the cookie, and that is what comes into the idea of putting the path, which would be basically a folder with the name of each your site and in it the relevant information for your server identify where is the data that it needs.

  • If it worked, mark the answer as correct to help other users.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.