在我的模型“用户”中,我在验证用户名/密码后获得以下授权
$db = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($db,'users','username','password');
$authAdapter->setIdentity($username);
$authAdapter->setCredential(md5($password));
$auth_result = $authAdapter->authenticate();
if( $auth_result->isValid() )
{
$auth = Zend_Auth::getInstance();
$storage = $auth->getStorage();
$storage->write($authAdapter->getResultRowObject(array('id','username')));
return 'logged_in';
}
return 'auth_failed';
它不断返回'auth_failed'。我在localhost上运行了代码,一切正常,但是当我在线上传它时,它无法授权用户。发生了什么事?
由于
答案 0 :(得分:0)
如果没有签入日志,我无法分辨出什么是错误的,所以也许你可能想要使用我用来存储auth数据的方法。基本上你手动验证并设置存储这不能解决问题,但如果不访问你的代码就不可能这样做。
function login($userNameSupplied,$passwordSupplied){
$table= new Application_Model_Dbtable_Users();//Or Whatever Table you're using
$row=$table->fetchRow($table->select()->where('username=?',$userNameSupplied)->where('password=?',md5($passwordSupplied));
if($row){
Zend_Auth::getInstance()->getStorage()->write($row->toArray());
return 'logged_in';
}
else{return 'failed';}
}
//To check if the user is logged in, use
$userInfo=Zend_Auth::getInstance()->getStorage()->read();
if($userInfo)//user is logged in