3
votes

I am working on web app in zend framwork and implementing login and logout coding in it.The auth adapters are working well. The problem is that, after authenticating and checking identity it shows the correct redirect url in the address bar, but the page shows the error instead of showing the view

here are the errors
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'session has already been started by session.auto-start or session_start()' in C:\Users\amrit\Zend\workspaces\DefaultWorkspace7\webDeveloper\library\Zend\Session.php on line 462

Zend_Session_Exception: session has already been started by session.auto-start or session_start() in C:\Users\TranceServe\Zend\workspaces\DefaultWorkspace7\webDeveloper\library\Zend\Session.php on line 462
and when I click refresh, its shows the correct view.The logout code is working well.

Here is my zend code

public function adminloginAction ()
{
    $login = new Admin_Form_Login();
    $login->setAction("adminlogin");
    $login->setMethod("POST");
    if (isset($_SESSION)) {
        echo ("start");
      } else {
        echo ("not started");
    }
    if ($this->_request->isPost() && $login->isValid($_POST)) {
        $adapter = new webDeveloper_Auth_StaffAdapter(
        $this->getRequest()->getParam("email"), 
        ($this->getRequest()->getParam("pwd")));
        $result = Zend_Auth::getInstance()->authenticate($adapter);
        if (Zend_Auth::getInstance()->hasIdentity()) {
           $this->_redirector->gotoUrl('/admin/index');
        } else {
            $this->_redirector->gotoUrl('/admin/adminauthentication/adminlogin');
        }
    }
    $this->view->form = $login;
}
5
Did you call session_start()?Nickool
I didn't call session_start anywhere().The session is created with auth adapter automatically when user have valid credentials ....Amritpal singh

5 Answers

1
votes

Mmm... It's already tells you all:

Zend_Session_Exception: session has already been started by session.auto-start

So try to check your php settings and switch off the session.auto-start.

But if it's not the case, then in your code try to check why are session started and by which component. May be you use some 3rd party stuff.

Xdebug with trace will help you to understand where and who does start the session.

6
votes

When zend_tool is used to create a project, it adds the following line to the application/configs/application.ini file :

resources.session.save_path = APPLICATION_PATH "/../data/session"

Check that this path exists and is writable by the app. Otherwise, Zf will send you this Exception with this bogus message.

3
votes

There was a big discussion about this on the German XING forums last year. One of the results was a quick and dirty fix, that simply starts a session in Bootstrap with this line of code:

Zend_Session::start();

In my opinion it's far from a real solution but the additional overhead is acceptable if most of your pages need the session anyway. But if you only need a session for some modules or parts of your project you really should go the Xdebug way.

1
votes

Probably it won't be your case, but same error message is thrown when you try to save your session into db table, which isn't created.

0
votes

It also happens when you try to handle your sessions into redis/couchbase check session.save_handler into php.ini