我在我的应用程序中安装了 zfcuser 模块,一切正常。我配置了主机名路由器,这里开始出现问题,当我登录主域 (http://example.com) 时一切正常,但是当我转到任何子域时 (http://test.example.com, http://anysubdomain.example.com)我正在失去登录状态,在每个子域上我都必须重新登录。如何跨子域共享登录状态?在 ZF1 中,我只是设置了“cookie_domain”,它可以工作,但如何在 ZF2 中实现呢?当然,我也在使用 Bjyauthorize,我想在子域上保留 bjyauthorize 守卫...
最佳答案
好的,我找到了解决方案,在我添加的 ZfcUser Module.php 中:
use Zend\Session\Config\SessionConfig;
use Zend\Session\SessionManager;
use Zend\Session\Container;
use Zend\EventManager\EventInterface;
public function onBootstrap(EventInterface $e)
{
$config = $e->getApplication()
->getServiceManager()
->get('Configuration');
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config['session']);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
在 ZfcUser module.config.php 中:
return array(
'session' => array(
'use_cookies' => true,
'cookie_domain'=>'example.com',
)
);
希望对大家有所帮助。
关于zend-framework2 - 如何在 zend framework 2 中跨子域共享 zfcuser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14113129/