Cake没有保存cookie,至少不是我能看到的,当我再次访问该页面时,我没有自动登录。我实际上想要实现“记住我的功能”#。我正在使用这个组件 https://github.com/ceeram/Authenticate/wiki/Set-Cookie
这是我的代码
login.ctp
echo $this->form->create();
echo $this->form->input('email');
echo $this->form->input('password');
<?php echo $this->Form->checkbox('remember_me', array('hiddenField' => false,'name' => 'remember_me'));?>
echo $this->form->end('submit');
?>
UserController中
<?php
class UsersController extends AppController {
public $components = array('Cookie');
public function beforeFilter() {
parent::beforeFilter();
$this->Cookie->type('rijndael');
$this->Security->requireSecure('login');// for security
$this->Auth->authenticate = array(
'Authenticate.MultiColumn' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'columns' => array('email', 'mobileNo'),
'userModel' => 'User',
)
);
}
public function index(){
}
public function login() {
$this->layout='userdefault';
if ($this->request->is('post')) {
//$this->Auth->logout();
$cookie = $this->Cookie->read('Auth.User');
debug($cookie);
if ($this->Auth->login()) {
$this->_setCookie($this->Auth->user('id'));
$this->redirect('/users/controlpanel');
} else {
$this->Session->setFlash('Incorrect Email/Password Combination');
}
}
}
protected function _setCookie($id) {
if (!$this->request->data('User.remember_me')) {
return false;
}
$data = array(
'username' => $this->request->data('User.email'),
'password' => $this->request->data('User.password')
);
$this->Cookie->write('User', $data, true, '+1 week');
return true;
}
public function logout() {
$this->redirect($this->Auth->logout());
}
public function controlpanel(){
$this->layout='controlpaneldefault';
}
}
?>
并且还告诉我如何检查或调试cookie以检查我的cookie是否保存或者是否无法进行调试然后告诉我如何设置cookie的名称以便我进入浏览器cookie并且搜索名称为
的cookie答案 0 :(得分:0)
插入exit();调试后($ cookie);检查cookie数据。