Differentiate PHP sessions between systems

1

I have encountered the following problem.

2 systems mounted with PHP and access management through the creation of sessions at the time of login.

At the time of entering one of the systems, I automatically also enabled the entry to the other system, I understand that it is because in each I raise and allow access by consulting if the variable of $_Session['usuario'] has been set.

My query is, how can you manage to create different sessions for each system if they run simultaneously? .

    
asked by Marcelo Beneventi 14.05.2018 в 18:45
source

1 answer

3

The sessions in PHP are identified by the cookies and it depends on the value of these each time a request is made. If your script does not have a session name then all your scripts will use the same session name for all the scripts and if these are above, they are in the same domain, then PHP will continue the previous session without any problem.

In handling sessions of each of your systems you need to use something like:

session_name('sistema_alpha');
session_start();

This must always be before session_start() , this way when logging into the system 1 system 2 will not start session because it will look for the cookie "system_beta" to check if it is valid and thus summarize or deny the session:

session_name('sistema_beta');
session_start();
    
answered by 14.05.2018 / 19:49
source