我遇到了Auth / ORM和auto_login的问题。我将生命周期设置为两周,但无论浏览器是否关闭,我都会在大约一小时后退出。实际上,它是基于时间的,因为即使在浏览器关闭的情况下,会话也会保持不变。
我已经设置了这样的东西(任何帮助都会受到赞赏!!!):
bootstrap.php中
Cookie::$salt = 'some random string here';
配置/ auth.php
<?php defined('SYSPATH') or die('No direct access allowed.');
return array(
'driver' => 'ORM',
'hash_method' => 'sha256',
'hash_key' => '<another random string>',
'lifetime' => 1209600, // TWO WEEKS, NO?
'session_type' => Session::$default,
'session_key' => 'auth_user',
// Username/password combinations for the Auth File driver
'users' => array(
),
);
类/控制器/ auth.php
public function action_login() { // Check to make sure the user isn't already logged in... if (Auth::instance()->logged_in() || Auth::instance()->auto_login()) {
$this->request->redirect($this->request->referrer()); }
$referrer = base64_encode($this->request->referrer());
$post = $this->request->post();
if (!empty($post))
{
$remember = isset($post['remember']); // <-- This value has been verified
Auth::instance()->login(Arr::get($post, 'email'), Arr::get($post, 'password'), $remember);
if (Auth::instance()->logged_in())
{
$this->request->redirect(base64_decode(Arr::get($post, 'referrer')));
}
else
{
$this->view->set('error', true);
}
if (isset($post['referrer']))
{
$referrer = Arr::get($post, 'referrer');
}
}
$this->view = Template::factory('auth/login');
$this->view->set('referrer', $referrer);
}
类/控制器/ website.php
class Controller_Website extends Controller {
public function before()
{
$parent_before = parent::before();
if (Auth::instance()->logged_in() || Auth::instance()->auto_login()) //<-- isn't this where the magic is supposed to be happening?!?!
{
$this->user = Auth::instance()->get_user();
}
elseif ($this->require_auth && !in_array($this->request->action(), $this->auth_allow_actions))
{
$this->request->redirect('/auth/login');
}
return $parent_before;
}
}
答案 0 :(得分:0)
尝试设置$ remember,如下所示:
$remember = array_key_exists('remember', $this->request->post()) ? (bool) $this->request->post('remember') : FALSE;