Zend_Auth getidentity always returns null
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 authenticat开发者_开发百科ion
$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
}
It sounds like the /tmp folder on your server is full meaning that if you're using file-based sessions, the session will always be empty. See if you can confirm it.
This snippet will tell you how full the disks are in the machine:
echo `df -h`."\n";
This snippet will confirm if you're using files and where they are stored.
echo ini_get('session.save_handler')."\n";
echo ini_get('session.save_path')."\n";
If the second ini_get has 'no value', then it'll default to /tmp
If the save path is within your home folder, then you can clear that out yourself, but if the save path is in /tmp or some other system folder, you'll need to get onto your hosting provider.
精彩评论