Experts,
I just found a weird behavior of Zend_Auth whereby it's not able to store session in the server. This happens just suddenly to all of my existing applications that use Zend_Auth for authentication purpose, so I'm sure it's not a problem with the codes. Basically, whenever the user is successfully authenticated (his user object is stored into the session) and after redirect to the landing page, the user object is always NULL.
I use Zend_Auth::getInstance()->getIdentity() to retrieve the user object from the session and it's always NULL. This weird behavior only happens in the live server and everything works just fine in my machine and staging server. I just want to make sure that it's just the server trying to be funny here coz I've been checking around the codes and still remain clueless. It's a shared server and I don't have much access.
Here is my code:
// setup Zend_Auth adapter for a database table
Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
$db = Zend_Registry::get('db');
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'Users', 'Email', 'Password', 'MD5(?) AND Active=1');
$authAdapter->setIdentity($email)
->setCredential($password);
// do the authentication
$auth = Zend_Auth::getInstance();
$result = $authAdapter->authenticate();
if ($result->isValid()) {
// success : store database row to auth's storage system
// (not the password though!)
$userData = array('UID','Email','Username','FirstName','LastName','Email','School');
$data = $authAdapter->getResultRowObject($userData, 'Password');
$auth->getStorage()->write($data);
$userData = get_object_vars($auth->getIdentity());
if (!empty($userData)) {
// redirect here
} else {
// show invalid
}
} else {
// show invalid
}