如何将会话的内容发送到记住我的cookie?

时间:2016-01-27 07:34:08

标签: php session cakephp remember-me

我正在努力记住cakephp中的cookie,让您登录2周。

它工作正常,但我传递的内容写在cookie上:

$this->request->data['User']['username']

每当注册新用户时,默认情况下会创建散列ID。

记住我的cookie只会生成一个密钥,用于检查它是否是相同的用户并在登录中登录。当cakephp创建的cookie过期时(默认为四小时),所有信息(如用户ID,地址等)都将丢失。

如何发送要检查的ID?

如何在四小时后存储所有这些(用户信息)? (比如大约2周)

1 个答案:

答案 0 :(得分:0)

像这样更改您的登录功能

 function login() {
    if ($this->Auth->user()) {
        if (!empty($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, '+2 weeks');
            unset($this->data['User']['remember_me']);
        }
        $this->redirect($this->Auth->redirect());
    }
    if (empty($this->data)) {
        $cookie = $this->Cookie->read('Auth.User');
        if (!is_null($cookie)) {
            if ($this->Auth->login($cookie)) {
                //  Clear auth message, just in case we use it.
                $this->Session->delete('Message.auth');
                $this->redirect($this->Auth->redirect());
            }
        }
    }
}