問題描述
我在嘗試加載 Zend Framework 應用程序時收到此錯誤:
I get this error when trying to load a Zend Framework application:
致命錯誤:未捕獲的異常帶有消息的Zend_Session_Exception"'會話已經由session.auto-start 或 session_start()'在/www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Session.php:462
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'session has already been started by session.auto-start or session_start()' in /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Session.php:462
堆棧跟蹤:
#0/www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Session/Namespace.php(143):Zend_Session::start(true)
#0 /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Session/Namespace.php(143): Zend_Session::start(true)
#1/www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Auth/Storage/Session.php(87):Zend_Session_Namespace->__construct('Zend_Auth')
#1 /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Auth/Storage/Session.php(87): Zend_Session_Namespace->__construct('Zend_Auth')
#2/www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Auth.php(91):Zend_Auth_Storage_Session->__construct()
#2 /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Auth.php(91): Zend_Auth_Storage_Session->__construct()
#3/www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Auth.php(141):Zend_Auth->getStorage()
#3 /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Auth.php(141): Zend_Auth->getStorage()
#4/www/htdocs/w00a1ed7/autospin/redaktion/application/layouts/scripts/layout.phtml(31):Zend_Auth->hasIdentity()
#4 /www/htdocs/w00a1ed7/autospin/redaktion/application/layouts/scripts/layout.phtml(31): Zend_Auth->hasIdentity()
#5/www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/View.php(108):包括('/www/htdocs/w00...')
#5 /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/View.php(108): include('/www/htdocs/w00...')
#6/www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/View/Abstract.php(831):Zend_View->_run('/www/htdocs/w00...')
#6 /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/View/Abstract.php(831): Zend_View->_run('/www/htdocs/w00...')
#7/www/htdocs/w00a1ed 在/www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Session.php在線 462
#7 /www/htdocs/w00a1ed in /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Session.php on line 462
我使用 Zend_Auth
并在我的本地服務器上運行良好,但在生產服務器上我收到了前面的錯誤,但不是每次都如此.
I Use Zend_Auth
and on my local server and it works well, but on a production server I get the preceding error, but not every time.
我已檢查 .htaccess
文件中的 session.autostart
是否設置為 0
.
I have checked that session.autostart
is set to 0
in the .htaccess
file.
我該如何解決這個錯誤?
How do I fix this error?
感謝您的回答,但我不會在任何地方使用 session_start().僅與采埃孚合作.
Thank you for your Answer, but I do not user session_start() anywhere. Work only with ZF.
我只在共享服務器上遇到這個問題,在我的本地服務器腳本上運行完美.
I Have this Problem only on shared server, on my local server script works perfectly.
我在此代碼中使用 INIT 函數:
I Use INIT Function with this code:
受保護的 $user;
protected $user;
public function init()
{
if(!Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('auth/login');
}else
{
$this->user = Zend_Auth::getInstance()->getIdentity();
}
}
我已經嘗試只在indexAction中設置tis代碼,這樣其他action就不用去破解Auth了...但是還是有問題.
I allready try to set tis code only in indexAction, so that other actions do not have to chack the Auth... but still have problems.
有沒有辦法在 Action 中設置不檢查會話或類似這樣的想法?
Ist there a way to set in an Action to do not check about session or somethink like this?
最好的問候
推薦答案
事情就是這樣.Zend_Auth
嘗試開始一個新的會話,因為 Zend_Session::start()
還沒有被調用.
It's what it says it is. Zend_Auth
tries to start a new session, since Zend_Session::start()
has not yet been called.
問題是必須在會話開始之前調用 Zend_Session::start()
.但是,由于 session.autostart 是 0(順便說一句,這是在 php.ini 中而不是 .htaccess 中),您可能已經編寫了 session_start();
某處.您不能這樣做,因為 ZF 希望完全控制會話,即您不應直接訪問全局會話變量.
The problem is that Zend_Session::start()
has to be called before a session is started. But, since session.autostart is 0 (btw this is in php.ini not .htaccess), you have probably written session_start();
somewhere. You're not allowed to do that, since ZF wishes to have full control over sessions, i.e. you shouldn't access the global session variable directly.
要解決它,請在您的代碼文件中搜索 session_start()
和其中之一
To solve it, search your code files for session_start()
and either
- 刪除所有出現,但只有一個.要注意它是否已經啟動,請設置
error_reporting(E_ALL|E_STRICT);
- 在所有地方用
Zend_Session::start();
替換它
如果你不能找到所有的出現,找到一個 session_start();這會困擾您的 Zend_Auth::getInstance()->hasIdentity()
并使用以下代碼段快速解決問題
If you can't find all occurrences, find the one session_start(); that bothers your Zend_Auth::getInstance()->hasIdentity()
and solve the problem quick n' dirty with the following snippet
try {
Zend_Session::start();
} catch(Zend_Session_Exception $e) {
session_start();
}
如果您在整個應用程序中使用 ZF,我會選擇 2)
If you're using ZF in your whole application, I would go with 2)
這篇關于“會話已經開始……"Zend Framework 應用程序中的異常的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!