redirect causing session not to write
Posted: Tue Dec 26, 2006 4:00 pm
I've got this login action in my user controller. It's supposed to write to a database table like this:
sessions:
id
user_id
user_ip
access
data
Everything works fine if I comment out the $this->_redirect('user/home'); line, but if I leave it in, the user_id column is null in the table. What in the world could be causing this?
sessions:
id
user_id
user_ip
access
data
Code: Select all
public function loginAction()
{
$db = Zend::registry('database');
$config = Zend::registry('config');
$rememberMeDays = $config->user->rememberMeDays;
require_once 'user/form/base.php';
require_once 'user/form/rules.php';
/**
* Assign defaults so no notices are thrown
*/
$this->_view->assign('formAction', 'user/login');
$this->_view->assign('message', '');
$this->_view->assign('rememberIsChecked', $rememberme->getChecked() ? 'checked="checked"' : '');
$this->_view->assign('rememberMeDays', $rememberMeDays);
$request = $this->getRequest();
$post = new Zend_Filter_Input($request->getPost());
if ($form->isSubmitted())
{
if($form->validate())
{
$username = $form->getSubmitValue('username');
$password = $form->getSubmitValue('password');
$remember = $form->getSubmitValue('remember');
$auth = new Zend_Auth(new MC2_Auth_Adapter());
$options = array(
'username' => $username,
'password' => $password,
'remember' => $remember
);
$token = $auth->authenticate($options);
if (!$token->isValid())
{
// Todo: just send them to login page with the message as a param
$this->_view->assign('message', $token->getMessage());
}
else
{
Zend_Session_Core::regenerateId();
$db_session = Zend::registry('db_session');
$db_session->setUserId($token->getIdentity());
Zend_Session_Core::writeClose();
$this->_redirect('user/home'); // If I comment out this line, all works fine.
}
}
}
$this->_view->assign('formData', $form->toArray());
$this->_view->assign('loginForm', $this->_view->render('user/form/login.tpl.php'));
$this->_view->assign('content', $this->_view->render('user/main.tpl.php'));
$response = $this->getResponse();
$response->setBody($this->_view->render('layout/main.tpl.php'));
}