Php – Fatal:error – session has already been started by session.auto-start or session_start()

PHPzend-framework

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;
}

Best Answer

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.

Related Topic