Alex Pliutau
Alex Pliutau

Reputation: 21957

Zend Session 2 common cookie domains

I have 3 domains:

example.com
m.example.com
dev.example.com

Session should be common for example.com and m.example.com. How I have made it. Bootstrap.php:

protected function _initSession()
{
        Zend_Session::setOptions(array(
            'cookie_domain' => '.example.com',
            'name'          => 'ExampleSession'
        ));
        Zend_Session::start();
}

But this session works for dev.example.com too. How I can avoid common session for dev.example.com? Thanks!

Upvotes: 0

Views: 843

Answers (1)

Andreas Linden
Andreas Linden

Reputation: 12721

well the only way I see to make this possible is to dynamically set the cookie domain depending on the hostname.

it could look something like this:

protected function _initSession()
{
        Zend_Session::setOptions(array(
            'cookie_domain' => ($_SERVER['HTTP_HOST'] == 'dev.example.com' ? 'dev.example.com' : '.example.com'),
            'name'          => 'ExampleSession'
        ));
        Zend_Session::start();
}

Upvotes: 3

Related Questions