【发布时间】:2022-01-30 23:50:22
【问题描述】:
我有时间结束会话。如果用户没有选中“remember_me”复选框 - 会话将持续 2 小时。当复选框被选中时 - 应该持续 - 48 小时。我有一个 loginСontroller,我在其中对登录结果做出反应,如果验证成功并且复选框 =“on”,您需要更改会话时间。我试图通过查看文档进行更改,并花了很多时间寻找解决方案。也许有人可以帮助我。非常感谢您[在此处输入图片描述]
这是我的文件 config/app.php
'Session' => [
'defaults' => 'php',
'ini' => [
'session.cookie_lifetime' => 7200,
]
],
这是我的登录控制器
`public function index()
{
$this->viewBuilder()->setLayout('main');
$this->set("title", "");
$this->set("description", "description");
$this->request->allowMethod(['get', 'post']);
$result = $this->Authentication->getResult();
// regardless of POST or GET, redirect if user is logged in
if ($result->isValid()) {
if ($this->request->getData('remember') == 'on') {
///// the solution should be here
}
$redirect = [
'controller' => 'Main',
'action' => 'index',
];
return $this->redirect($redirect);
}
// display error if user submitted and authentication failed
if ($this->request->is('post') && !$result->isValid()) {
$this->Flash->saved_error(__('Invalid email or password'));
}
}`
【问题讨论】:
标签: php authentication cookies cakephp cakephp-4.x