如何将会话的内容发送到记住我的 cookie?
how to send session's content to a remember me cookie?
我正在 cakephp
中制作记住我的 cookie,它可以让您保持登录状态 2 周。
它工作正常,但我传递给 cookie 的内容:
$this->request->data['User']['username']
无论何时注册新用户,都会默认创建一个散列 ID。
记住我的 cookie 只是生成一个密钥,用于检查它是否是同一用户并在后台登录。当cakephp创建的cookie过期时(默认为四小时),用户ID,地址等所有信息都会丢失。
如何发送要检查的 ID?
如何在四个小时后存储所有这些(用户信息)? (比如大约 2 周)
像这样更改您的登录功能
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());
}
}
}
}
我正在 cakephp
中制作记住我的 cookie,它可以让您保持登录状态 2 周。
它工作正常,但我传递给 cookie 的内容:
$this->request->data['User']['username']
无论何时注册新用户,都会默认创建一个散列 ID。
记住我的 cookie 只是生成一个密钥,用于检查它是否是同一用户并在后台登录。当cakephp创建的cookie过期时(默认为四小时),用户ID,地址等所有信息都会丢失。
如何发送要检查的 ID?
如何在四个小时后存储所有这些(用户信息)? (比如大约 2 周)
像这样更改您的登录功能
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());
}
}
}
}