Zend_Session 不允许您销毁和重新创建会话 [英] Zend_Session doesn't allow you to destory and recreate a session
问题描述
我的要求是,当用户代理更改会话时应该销毁,并且应该启动新会话.但是如果在 start() 之前调用了 destroy ,则 Zend_Session::start() 会抛出异常.
<前><代码>尝试 {Zend_Session::start();} catch (Zend_Session_Exception $e) {Zend_Session::destroy(true);Zend_Session::start();//在这里打断Zend_Session::regenerateId();}Zend_Session::registerValidator(new Zend_Session_Validator_HttpUserAgent());例外:
未捕获的异常Zend_Session_Exception",消息为会话在此请求期间被显式破坏,不允许尝试重新启动."在 library\Zend\Session.php:431
原因是第二个 start() 命令如果已经在该请求中被调用,则会被静默忽略.我已经发布了一个问题,希望他们接受它..
请投票
http://framework.zend.com/issues/browse/ZF-11420
伙计们,我已经自己解决了
尝试{Zend_Session::start();} catch (Zend_Session_Exception $e) {Zend_Session::destroy(true);$this->bootstrap('frontController');$front = $this->getResource('frontController');$front->setRequest(new Zend_Controller_Request_Http());$front->setResponse(new Zend_Controller_Response_Http());$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');$redirector->gotoUrl($front->getRequest()->getRequestUri(),array('prependBase' => false));}
My requirement is, When user agent change session should destroy, and it should start new session. But Zend_Session::start() is throwing an exception if destroy was called before start().
try {
Zend_Session::start();
} catch (Zend_Session_Exception $e) {
Zend_Session::destroy(true);
Zend_Session::start(); // breaking here
Zend_Session::regenerateId();
}
Zend_Session::registerValidator(new Zend_Session_Validator_HttpUserAgent());
Exception:
Uncaught exception 'Zend_Session_Exception' with message 'The session was explicitly destroyed during this request, attempting to re-start is not allowed.' in library\Zend\Session.php:431
EDIT:
The reason is the second start() command is silently ignored if it was already called in that request. I have posted an issue, Hope they accept it..
if (self::$_sessionStarted) {
return; // already started
}
Please vote it
http://framework.zend.com/issues/browse/ZF-11420
Guys I have solved it my self
try {
Zend_Session::start();
} catch (Zend_Session_Exception $e) {
Zend_Session::destroy(true);
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$front->setRequest(new Zend_Controller_Request_Http());
$front->setResponse(new Zend_Controller_Response_Http());
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl($front->getRequest()->getRequestUri(),array('prependBase' => false));
}
这篇关于Zend_Session 不允许您销毁和重新创建会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!