Ric*_*ing 7 session-cookies zend-session zend-framework2
我已经设置了两个用户帐户模块 - 管理员和客户.我目前的设置意味着如果您登录管理员我的应用程序认为您也是以客户身份登录.我决定的解决方案是创建一个会话,其中cookie路径基于管理员URL,即设置cookie_path为/administrator.
在我的管理员Module.php onBootstrap功能中,我包括:
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions(['cookie_path' => '/administrator']);
$sessionManager = new SessionManager($sessionConfig, null, null);
Container::setDefaultManager($sessionManager);
Run Code Online (Sandbox Code Playgroud)
它设置了cookie路径,但这会影响整个应用程序; 即网站的其余部分是无cookie的,因为网址不是以网页开头的/administrator.
如何设置我的应用程序,cookie_path以便我的管理员模块与应用程序的其余部分不同?
我所追求的是两个cookie - 一个用于管理路径,一个用于应用程序的其余部分.
我Zend\Authentication\AuthenticationService用于ACL.我想要实现的是让用户登录网站的客户部分并执行操作,然后登录管理面板进行操作.
例如,Magento将在处理客户帐户登录时设置一个cookie,然后在处理管理员帐户登录时设置另一个cookie.
如何设置Zend\Authentication\AuthenticationService基于url/module使用第二个会话或cookie?
要在身份验证服务上设置新的命名空间,请执行以下操作:
$auth = $e->getApplication()->getServiceManager()->get('Zend\Authentication\AuthenticationService');
$auth->setStorage(new \Zend\Authentication\Storage\Session($_namespace));
Run Code Online (Sandbox Code Playgroud)
在我的问题中,我想为我的管理区域创建一个不同的会话。在我的抽象控制器中(我正在$auth根据我的 acl 设置检查详细信息)我有:
$params = $e->getRouteMatch()->getParams();
/** @var \Zend\Authentication\AuthenticationService */
$auth = $e->getApplication()->getServiceManager()->get('Zend\Authentication\AuthenticationService');
$_namespace = current(explode('\\', $params['__NAMESPACE__']));
// Most generic session namespace.
if(in_array($_namespace, ['Customer', 'Application', null])) {
$_namespace = 'Zend_Auth';
}
$auth->setStorage(new \Zend\Authentication\Storage\Session($_namespace));
Run Code Online (Sandbox Code Playgroud)
这不会创建第二个 cookie,但它确实意味着我可以转到domain.dev/account(客户部分)并能够独立于domain.dev/administrator(管理部分)登录,这最终是我试图做的。
| 归档时间: |
|
| 查看次数: |
130 次 |
| 最近记录: |