views:

156

answers:

2

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?

A: 

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

Frankie
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.
Brian
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.
Frankie
Putting Zend_Session::start(); ebfore verything seems to yield the same result. Any ideas?
Brian
+1  A: 

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

Jacob Fike