Manish Patel
Manish Patel

Reputation: 1957

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 share the same Session? For example, suppose you have instances running at:

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

If you login in the first instance and access instance2, you’ll see that you will already be logged in. This happens because Cakephp, per default, uses the PHP Session storage mechanism.

If this is not the behaviour you expect, Cakephp allows you to choose from three options for the Session handling 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 make Cakephp store the Session variables in the app/tmp/sessions directory. If you do it, remember to create and give the appropriate permissions to this directory.

Voilá, that’s all you need to do have separate Sessions for each of your Cakephp instances.

Upvotes: 4

Views: 1452

Answers (1)

Pranav
Pranav

Reputation: 174

Please open the core.php & change the application cookie path then session will be store according to application cookie path 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  
    ));

Upvotes: 5

Related Questions