Laravel 5-永远保持登录状态 [英] Laravel 5 - stay logged in forever

查看:122
本文介绍了Laravel 5-永远保持登录状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 login 页中放入一个复选框保持登录状态".

I wanted to put in the login page a checkbox "stay logged in".

除非用户注销,否则永远都不应结束用户的会话.

That should never end the session of the user unless the user logs out.

我知道在app/config/session.php中,我有以下变量:

I know that in app/config/session.php I have these variables:

'lifetime' => 60,

'expire_on_close' => false,

但是我想永久保持会话状态,如果用户关闭导航器,则不希望删除会话.

But I wanted to maintain alive the session forever, and not be removed if the user close his navigator.

关于我应该如何进行的任何想法?谢谢

Any ideas on how should I proceed? Thanks

推荐答案

Laravel具有

Laravel has a built-in feature to remember users, I'd strongly recommend using it.

如果您想在自己的帐户中提供记住我"功能应用程序,您可以将布尔值作为第二个参数传递给try方法,将使用户保持身份验证无限期,或者直到他们手动注销.当然,您的用户表必须包含字符串Remember_token列,该列将是用来存储记住我"令牌.

If you would like to provide "remember me" functionality in your application, you may pass a boolean value as the second argument to the attempt method, which will keep the user authenticated indefinitely, or until they manually logout. Of course, your users table must include the string remember_token column, which will be used to store the "remember me" token.

if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) {
    // The user is being remembered...
}

如果您想手动解决问题,可以使用以下解决方法:您必须将Cookie的过期日期设置为较宽泛的将来的日期(有点像2050).从技术上讲,这并不是永远的,但通常足够长的时间.

if you want to solve the problem manually, there is workaround for this: you have to set the expires date of your cookie to a date in the wide future, somewhat like 2050. this is technically not forever, but should usually be long enough.

这篇关于Laravel 5-永远保持登录状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆