zend-framework2 - 如何在 zend framework 2 中跨子域共享 zfcuser

标签 zend-framework2 zfcuser

我在我的应用程序中安装了 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/

相关文章:

zend-framework2 - ZfcUser 中的用户状态究竟是什么?

zend-framework2 - 禁用默认 zfcUser 路由?

php - 使用 ZfcUser 对 Controller 进行简单的 ZF2 单元测试

annotations - 如何使用注释在我的项目中使用 Doctrine 2 调整模块 ZfcUser/zfcuserDoctrineORM?

php - INET_ATON 在 where 语句 doctrine2 querybuilder zend2

php - 如何在ZF2中对MySQL数据库表的特定属性设置条件?

php - 在 ZF2 中使用 ZfcUser 生成用户帐户

netbeans - Zend 框架 2 和 netbeans Xdebug 的问题

layout - ZF2 EdpModuleLayouts

rest - ExceptionStrategy 不适用于 JsonStrategy