专家们,
我刚刚发现 Zend_Auth 的一个奇怪行为,它无法在服务器中存储会话。这只是突然发生在我所有使用 Zend_Auth 进行身份验证的现有应用程序中,所以我确信这不是代码问题。基本上,每当用户成功通过身份验证(他的用户对象存储到会话中)并重定向到登录页面后,用户对象始终为 NULL。
我使用 Zend_Auth::getInstance()->getIdentity() 从会话中检索用户对象,它始终为 NULL。这种奇怪的行为只发生在实时服务器中,并且在我的机器和登台服务器中一切正常。我只是想确保这只是服务器试图在这里搞笑,因为我一直在检查代码,但仍然一无所知。这是一个共享服务器,我没有太多访问权限。
这是我的代码:
// 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
}