Posts Tagged ‘session’

php session operations

February 26th, 2010

* get session id: session_id(), but remember to session_start() before getting the id.

* session_decode($data), this will decode the data and store them into $_SESSION.


Zend_Session_SaveHandler_DbTable doen’t work

January 15th, 2010

My current ZF version is 1.9.4. However, because my application started from 1.7.x, I wrote all bootstrap code in index.php. So we config Zend_Session_SaveHandler_DbTable like this as the document said in index.php:

$config = array(
‘name’                 => ‘session’,
‘primary’              => ‘id’,
‘modifiedColumn’  => ‘modified’,
‘dataColumn’        => ‘data’,
‘lifetimeColumn’    => ‘lifetime’
$saveHandler = new Zend_Session_SaveHandler_DbTable($config);

And in indexAction of IndexController, I tried to test it like this:

$session = new Zend_Session_Namespace();
$session->name = “newsbag”;

But nothing happened. There was no data inserted into the session table.

But later, I create a totally new blank project following the Quick Start of ZF & Tutorial: Getting Started with Zend Framework 1.9, it worked!

Still trying to figure out what the problem…

========== update 1 ============

Now the problem seems to be caused by the Zend_Controller_Front instance in index.php. Because when I tried to add self-defined routers in index.php in the blank project mentioned above like this:

require_once ‘Zend/Controller/Router/Route.php’;
$config = new Zend_Config_Ini (‘../configs.application.ini’, ‘routers’);
$router = new Zend_Controller_Router_Rewrite();

the Zend_Session_SaveHandler_DbTable refused to work.

So DON”T instance Zend_Controller_Front in index.php.

BTW, the possible way to set routers in ZF (>= 1.8.0) would be in Bootstrap.php:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
function _initRouter(array $options = null) {
$frontController = $this->getResource(‘FrontController’);
$config = new Zend_Config_Ini (‘../application/configs/application.ini’, ‘routers’);
$router = new Zend_Controller_Router_Rewrite();