This is my table:
CREATE TABLE `Sessions` (
`id` varchar(32) NOT NULL,
`modified` int(11) default NULL,
`lifetime` int(11) default NULL,
`data` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
This is in my bootstrap:
$sessionConfig = array(
'name' => 'Sessions', //table name as per Zend_Db_Table
'primary' => 'id', //the sessionID given by php
'modifiedColumn' => 'modified', //time the session should expire
'dataColumn' => 'data', //serialized data
'lifetimeColumn' => 'lifetime' //end of life for a specific record
);
$saveHandler = new Zend_Session_SaveHandler_DbTable($sessionConfig);
//cookie persist for 30 days
Zend_Session::rememberMe($seconds = (60 * 60 * 24 * 30));
//make the session persist for 30 days
$saveHandler->setLifetime($seconds)
->setOverrideLifetime(true);
//similarly,
//$saveHandler->setLifetime($seconds, true);
Zend_Session::setSaveHandler($saveHandler);
Zend_Session::start();
When I log in, nothing ever gets written to the Sessions table and I am logged out on the very next pageview.
Any ideas? I'm trying to have my users be perpetually logged in. Am I missing something in my login controller possibly?
You have to initialize your DB handler before telling Zend_Session to use the DB, either by setting a default adapter for Zend_Db, or passing your adapter in the config array as 'db'.
Had the same problem with an implementation of redis as session handler.
For me, putting the method
_initSession
as first method in my bootstrap class works.Hope it will help someone.
Maybe you have to put
Zend_Session::start();
before anything else on the page... ?I just managed to get this working:
My application.ini:
my bootstrap.php:
This function was placed as first function in the bootstrap.php, because sessions are started, when you construct a Zend_Session_Namespace object for the first time. If you do this, before the _initSession()-function got called, a standard file-based session may be started.
Finally, the session.sql:
Somewhere i read that the table must be InnoDB.