I want the code which allows us to do multiple logins in same window using zend framework. Currently when i try to do multiple logins in same window its gives me an error.
If not possible to do multiple logins in same window 开发者_StackOverflowthen is it possible to logout from first account when you try to login to another account?
And by multiple login i mean to say logging in using two different accounts in the different tabs of same browser.
Code for authentication:
$authAdapter = $this->_getAuthAdapter();
$login = $form->getvalue('login');
if($auto!="1")
$password = md5($form->getvalue('password'));
else
$password = $form->getvalue('password');
$authAdapter->setIdentity($login) ->setCredential($password);
$auth = Zend_Auth::getInstance();
try{
$result = $auth->authenticate($authAdapter);
} catch (Zend_Exception $e){
$this->view->errorMessage = $e->getMessage();
}
By default, Zend_Auth
persists the identity using a standard session. If the browser shares the session across tabs (I'm not sure there's a browser that doesn't), then you can't authenticate two different identities.
[Note on browser tabs: In testing I've use 'incognito' tabs in Chrome to login twice (other browsers have similar privacy features). However even then, Chrome shares the session across all 'incognito' tabs.]
To allow dual logins, you could use a custom method to persist the identity. But this will likely be a complex thing to do. Using some kind of token in the URI would allow the application to differentiate between the requests of two tabs assuming the second tab wasn't opened by the first.
You can logout the original user on second login, using something like this in your login code:
if($auth->hasIdentity()){
$auth->clearIdentity()
}
精彩评论