5

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?

4 Answers 4

2

I just managed to get this working:

My application.ini:

resources.db.isDefaultTableAdapter = true resources.db.adapter = "pdo_mysql" resources.db.params.host = "localhost" resources.db.params.dbname = "dbname" resources.db.params.username = "username" resources.db.params.password = "password" 

my bootstrap.php:

protected function _initSession() { $resource = $this->getPluginResource('db'); $dbAdapter = $db = $resource->getDbAdapter(); Zend_Registry::set("db", $dbAdapter); Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter); $config = array( 'name' => 'session', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime', 'db' => $dbAdapter ); Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config)); Zend_Session::start(); } 

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:

DROP TABLE IF EXISTS `session`; CREATE TABLE `session` ( `id` char(32) NOT NULL DEFAULT '', `modified` int(11) DEFAULT NULL, `lifetime` int(11) DEFAULT NULL, `data` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

Somewhere i read that the table must be InnoDB.

Sign up to request clarification or add additional context in comments.

1 Comment

You don't need both Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter); and 'db' => $dbAdapter
1

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'.

Comments

0

Maybe you have to put Zend_Session::start(); before anything else on the page... ?

3 Comments

I've read that you want to call Zend_Session::start(); after everything else. One reason being session_set_cookie_params() which is called from rememberMe() cannot set the lifetime after the session is started.
Even so, if you set ´Zend_Session::start();´ before anything else does it work? That could give us some clues to what may be interfering.
Putting Zend_Session::start(); ebfore verything seems to yield the same result. Any ideas?
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.