“session has already been started…” exception in Z

2019-02-06 11:14发布

I get this error when trying to load a Zend Framework application:

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

Stack trace:

#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')

#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()

#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): include('/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 in /www/htdocs/w00a1ed7/autospin/redaktion/library/Zend/Session.php on line 462

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.

I have checked that session.autostart is set to 0 in the .htaccess file.

How do I fix this error?


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.

I Use INIT Function with this code:

protected $user;

public function init()
{   
    if(!Zend_Auth::getInstance()->hasIdentity())
    {
        $this->_redirect('auth/login');
    }else
    {
        $this->user = Zend_Auth::getInstance()->getIdentity();
    }
}

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.

Ist there a way to set in an Action to do not check about session or somethink like this?

Beste regards

11条回答
闹够了就滚
2楼-- · 2019-02-06 11:35

If you are developing applications with the RPCL library (RADPHP) and you are getting this error:

Application raised an exception class Zend_Session_Exception with message 'session has already been started by session.auto-start or session_start()',

then here is my solution.

You will be surprised how simple it is. Simple include the line

require_once("zcommon.inc.php");

just after the opening PHP tag in the file containing ZAuth component – usually this is the file with a DataModule form. Of course make sure the file zcommon.inc.php is in your path. This will ensure that the Zend session will start first instead of the RPCL session.

Also make sure the name of the php files in your application correspond to the name of the containing classes.

查看更多
唯我独甜
3楼-- · 2019-02-06 11:39

had the same error. it occured only if two instances of the same session were used at the same time (e.g. two browser instances were loading at the same time). This is a result of php not being able to handle two open sessions with the same id at the same time.

查看更多
对你真心纯属浪费
4楼-- · 2019-02-06 11:39

For those moving from one server to another. Another issue can be user that apache runs under. I was running a different user on my old box that was set on the new one. I used configs from my old httpd.conf, and forgot to update the permissions on /var/lib/php/session to reflect the different user.

To test, I changed the perms to 777. Everything worked fine, error was gone:

# cd /var/lib/php
# chmod 0777 session

So I returned the perms and changed the group. Of course change newApacheUser to the user account you are running httpd on IF NOT apache.

# chmod 0770 session
# chown root:newApacheUser session

Something to check out if your still having this issue:

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'session has already been started by session.auto-start or session_start()'

查看更多
【Aperson】
5楼-- · 2019-02-06 11:40

There are 3 major reasons that produce this issue:

  1. session.auto_start should be set to 0 or off. You can check it by placing phpinfo(); in any file and try to access it in browser, then search auto_start is it 0 or off. If not then set it off or 0.
  2. Check session path session.save_path in configuration at server. If with default configuration it's displaying error 'session has already been started by session.auto-start or session_start()', set it to '/temp'
  3. May be you have used session_start() in your code before zend session initialization.

In most cases the 2nd option is the reason.

查看更多
做个烂人
7楼-- · 2019-02-06 11:45

Before this drives you mad, there's probably nothing wrong with your code!

Check your application.ini for the session save path, for me it is APPLICATION_PATH '/session'

Now check you have the correct permissions! If not then cd into the application folder and type

sudo chmod 777 session
sudo chown -R [usernamehere] session
sudo chgrp -R [usernamehere] session

Job Done!

查看更多
登录 后发表回答