我试图让我的登录()函数与'记住我'的工作。CakePHP登录()与'记住我'导致无限循环
function login() {
if ($this->Auth->user()) {
if (!empty($this->data) && $this->data['User']['remember_me']) {
$cookie = array();
$cookie['username'] = $this->data['User']['username'];
$cookie['password'] = $this->data['User']['password'];
$this->Cookie->write('Auth.User', $cookie, true, COOKIE_EXPIRE);
unset($this->data['User']['remember_me']);
}
$this->LogDetail->Write('activity','has logged IN');
$this->redirect($this->Auth->redirect());
}
if (empty($this->data)) {
$cookie = $this->Cookie->read('Auth.User');
if (!is_null($cookie)) {
if ($this->Auth->login($cookie)) {
$this->Session->destroy('Message.Auth'); # clear auth message, just in case we use it.
$this->LogDetail->Write('activity','has been authenticated via cookie and is now logged IN');
$this->redirect($this->Auth->redirect());
} else {
$this->LogDetail->Write('activity','attempted to gain access with an invalid cookie');
$this->Cookie->destroy('Auth.User'); # delete invalid cookie
$this->Session->setFlash('Invalid cookie');
$this->redirect('login');
}
}
}
}
它首先检查是否在会话中授权用户。
如果用户在会话中被授权,它会将它们重定向到目标页面。
如果因为用户提交了登录表单而被授权进行会话,它会检查是否选中了“记住我”,然后在重定向之前创建cookie。
如果用户未在会话授权,对于存在的Auth.User的cookie,然后将函数检查试图Auth->登录($ cookie中)。
这是问题发生的地方。
如果没有会话但拥有Auth.User cookie的用户访问该站点,它会永久重定向,一次又一次地向日志写入“已通过cookie进行身份验证并且现在已登录”,直到浏览器终止。
我很困惑,因为$ this-> Auth-> login($ cookie)返回true,但SESSION没有被更新!
Auth-> login($ cookie)如何返回true,但会话的auth信息保持未设置(导致无限循环)?
在观看cookie的萤火虫在无限循环中,我注意到,在此过程中
我还要提到的是,登录系统/认证/重定向等正常工作时,没有CakePHP的会话cookie是不断变化的值Auth.User Cookie是目前
如果有人可以帮助我弄清楚了这一点,我将不胜感激
谢谢
会话 - >销毁是问题!非常感谢 – samJL 2011-05-26 16:18:38