doumi1912 2016-05-29 15:35
浏览 87

Laravel 5让我登录

I'm trying a simple login form in laravel with Auth class, what I notice is that it keeps me logged in even if I close the browser or restart the computer. I want a login that keeps me logged in only while the tab is open. How can I do that? The code from the controller:

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";

}

}

}
  • 写回答

2条回答 默认 最新

  • douxieqiu0651 2016-05-29 15:37
    关注

    In config/session.php set expire_on_close to 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,
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用