我正在使用Auth类在laravel中尝试一个简单的登录表单,我注意到它即使关闭浏览器或重新启动计算机也会让我保持登录状态。我想要一个登录,只有在选项卡打开时才能让我登录。我怎样才能做到这一点? 来自控制器的代码:
public function doLogin()
{
$rules = array(
'username' => 'required',
'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters
);
// run the validation rules on the inputs from the form
$validator = Validator::make(Input::all(), $rules);
// if the validator fails, redirect back to the form
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form
} else {
// create our user data for the authentication
$userdata = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
// attempt to do the login
if (Auth::attempt($userdata)) {
// validation successful!
// redirect them to the secure section or whatever
// return Redirect::to('secure');
// for now we'll just echo success (even though echoing in a controller is bad)
return Redirect::to('user');
} else {
// validation not successful, send back to form
echo "username ose pass gabim";
}
}
}
答案 0 :(得分:0)
在config/session.php
设置expire_on_close
至true
。
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 120,
'expire_on_close' => false,
答案 1 :(得分:0)
config/session.php
'expire_on_close' => false,
到
'expire_on_close' => true,