I’ve just wasted a few hours trying to get Zend_Session (part of the PHP Zend Framework) working correctly – previously, on this codebase, I had “rolled my own” cookie and session management system, but I thought I’d do it properly and utilise the Zend_Session system and store it all in a database…
It didn’t work.
Short answer as to why my sessions weren’t saving into the database (even after I switched to using the “default” Zend_Session_SaveHandler_DbTable ) was that I was setting up the session within the “routeStartup” section of Initalizer.php (which is loaded, in MVC fashion, via the bootstrap.php file). Changing bootstrap.php to:
// Prepare the front controller.
$frontController = Zend_Controller_Front::getInstance();
// Change to 'production' parameter under production environemtn
$frontController->registerPlugin(new Initializer('development'));
$maxSessionTime=60*60*24*30*6; // six months
Zend_Session::setSaveHandler(new My_Session_DbTable($maxSessionTime));
Zend_Session::rememberMe($maxSessionTime);
(i.e. take move the session savehandler out of the Initializer, but keep all the $thingy=new Zend_Session_Namespace whereever they are needed) means it started to work.
Most annoying thing: that there was no reason it didn’t work (no warnings, no errors, no documentation hints and no ‘out of place feeling’). Meh.
This post is over 6 months old.
This means that, despite my best intentions, it may no longer be accurate.
This blog holds over 12 years of archived content - during that time, I may have changed my opinion of something, technology will have advanced (and old "best standards" may no longer be the case), my technology "know how" has improved etc etc - it would probably take me a considerable amount of time to update all the archival entries: and defeat the point of keeping them anyway.
Please take these posts for what they are: a brief look into my past, my history, my journey and "caveat emptor".
I’ll try to get someone here who can explain why it didn’t work. Thanks for the feedback.
,Wil
Many thanks Wil – if you want me to send a code example, I certainly will (although it was a base Zend Studio “Zend Framework” project with just the session code added). I didn’t think of reporting it as a bug as I thought it may just be my misunderstanding of the framework.