views:

77

answers:

1

I am using Zend_Session_SaveHandler_DbTable to store my sessions in the database. I have the following in my application.ini

resources.session.save_path = APPLICATION_PATH "/../data/sessions"
resources.session.use_only_cookies = true
resources.session.remember_me_seconds = 864000
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "session"
resources.session.saveHandler.options.primary.session_id = "session_id"
resources.session.saveHandler.options.primary.save_path = "save_path"
resources.session.saveHandler.options.primary.name = "name"
resources.session.saveHandler.options.primaryAssignment.session_id = "sessionId"
resources.session.saveHandler.options.primaryAssignment.save_path = "sessionSavePath"
resources.session.saveHandler.options.primaryAssignment.name = "sessionName"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "session_data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"
resources.session.saveHandler.options.userIdColumn = "user_id"

The sessions seem to save correctly in the database.

The problem is that when I call Zend_Auth::getInstance()->hasIdentity() in the application, it will eventually call Zend_Session::start(true) which will cause the error:

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'session has already been started by session.auto-start or session_start()' in C:\Program Files (x86)\Zend\Apache2\htdocs\myapp\library\Zend\Session.php:462 Stack trace: #0 C:\Program Files (x86)\Zend\Apache2\htdocs\myapp\library\Zend\Session\Namespace.php(143): Zend_Session::start(true) #1 C:\Program Files (x86)\Zend\Apache2\htdocs\myapp\library\Zend\Auth\Storage\Session.php(87): Zend_Session_Namespace->__construct('Zend_Auth') #2 C:\Program Files (x86)\Zend\Apache2\htdocs\myapp\library\Zend\Auth.php(91): Zend_Auth_Storage_Session->__construct() #3 C:\Program Files (x86)\Zend\Apache2\htdocs\myapp\library\Zend\Auth.php(141): Zend_Auth->getStorage() #4 C:\Program Files (x86)\Zend\Apache2\htdocs\myapp\application\modules\default\views\scripts\layout.phtml(29): Zend_Auth->hasIdentity() #5 C:\Program Files (x86)\Zend\Apache2\htdocs\myapp\library\Zend\View.php(108): include('C:\Prog in C:\Program Files (x86)\Zend\Apache2\htdocs\myapp\library\Zend\Session.php on line 462

since Zend_Session_SaveHandler_DbTable already started the session. I though that Zend_Session_SaveHandler_DbTable would automatically have Zend_Auth store the session information in the database.

Is there something I am missing here or have not configured correctly?

A: 

the documentation(http://framework.zend.com/manual/en/zend.application.available-resources.html#zend.application.available-resources.session) is incorrect for setting up the save handler in the application.ini

it should be:

resources.session.save_path = APPLICATION_PATH "/../data/sessions" resources.session.use_only_cookies = true resources.session.remember_me_seconds = 864000 resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable" resources.session.saveHandler.options.name = "session" resources.session.saveHandler.options.primary[] = "session_id" resources.session.saveHandler.options.primary[] = "save_path" resources.session.saveHandler.options.primary[] = "name" resources.session.saveHandler.options.primaryAssignment[] = "sessionId" resources.session.saveHandler.options.primaryAssignment[] = "sessionSavePath" resources.session.saveHandler.options.primaryAssignment[] = "sessionName" resources.session.saveHandler.options.modifiedColumn = "modified" resources.session.saveHandler.options.dataColumn = "session_data" resources.session.saveHandler.options.lifetimeColumn = "lifetime"

I've submitted the ZF issue: http://framework.zend.com/issues/browse/ZF-10471

Christopher