Zend Session 2常见的cookie域

时间:2013-06-20 07:43:38

标签: php apache zend-framework session subdomain

我有3个域名:

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

会话应该是example.comm.example.com的常见内容。我是怎么做到的。 bootstrap.php中:

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

但此会话也适用于dev.example.com。如何避免dev.example.com的常见会话?谢谢!

1 个答案:

答案 0 :(得分:3)

我认为实现这一目标的唯一方法是根据主机名动态设置cookie域。

它看起来像这样:

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();
}