Multiple Sessions for Different Instances of CakePHP in the Same Domain

Did you know that if you run multiple instances of the same application in Cakephp in the same domain, they will use the same session? For example, suppose instances are executed using:

www.example.com/instance1 and www.example.com/instance2

If you log into the first instance and access instance2, you will see that you are already logged in. This is because Cakephp uses the PHP session storage engine by default.

If this is not the behavior you expect, Cakephp allows you to choose one of three options for the session processing method: php (default), cake, and database. The current method is stored in the Session.save variable in app / config / core.php.

Changing the method from php to cake will cause Cakephp to save the Session variables in the app / tmp / sessions directory. If you do, be sure to create and grant the appropriate permissions for this directory.

Voilá, this is all you need to do to have separate sessions for each of your Cakephp instances.

+4
source share
1 answer

Please open core.php and change the path to the application file, then the session will be stored in accordance with the application cookie pool For www.example.com/instance1

Configure::write('Session', array(
        'defaults' => 'database',
        'ini' => array(
            'session.cookie_path' => '/instance1',
        ),
        'cookie' => 'instance1',
        'cookieTimeout' => 0,   
           'checkAgent'  => false  
    ));

For www.example.com/instance2

Configure::write('Session', array(
        'defaults' => 'database',
        'ini' => array(
            'session.cookie_path' => '/instance2',
        ),
        'cookie' => 'instance2',
        'cookieTimeout' => 0,   
           'checkAgent'  => false  
    ));
+4
source

All Articles