Laravel:从应用程序注销/清除所有用户的所有会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36646902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:37:13  来源:igfitidea点击:

Laravel: Logout/clear all sessions for all users from app

phplaravelsession

提问by Jason McCreary

The Problem

问题

I want to clear allsessions for allusers in my Laravel application.

我想清除Laravel 应用程序中所有用户的所有会话。

What I have tried

我试过的

I understand that Auth::logout()will log out a single user, but not allusers. I have also tried deleting the session files from storage/framework/sessions. Neither have worked.

我知道这Auth::logout()将注销单个用户,但不是所有用户。我还尝试从storage/framework/sessions. 两者都没有工作。

I am using the built in Authentication(e.g. Auth) and the file driver for sessions running Laravel 5.2.

我正在为运行 Laravel 5.2 的会话使用内置的身份验证(例如Auth)和文件驱动程序。

How can I effectively force logout for all logged in users so they have to log in again?

如何有效地强制所有登录用户注销以便他们必须再次登录?

回答by Dakota Trotter

It's worth noting that Laravel actually only stores active sessions in the session folder; those that are 'remembered' but haven't been actively accessing your application do not count among these sessions. As such, just deleting the files won't finish the job.

值得注意的是,Laravel 实际上只将活动会话存储在会话文件夹中;那些被“记住”但没有主动访问您的应用程序的会话不计入这些会话中。因此,仅仅删除文件并不能完成工作。

You must also clear all Remember Tokens from the users table, as this token is used in conjunction with the local token stored in the cookie to re-create the session when a user reconnects.

您还必须清除用户表中的所有记住令牌,因为此令牌与存储在 cookie 中的本地令牌结合使用,以在用户重新连接时重新创建会话。

回答by Muhamad Yulianto

in app/session.php you can change cookie value, so user will automatically logout because of cookie is not match with the config

在 app/session.php 你可以改变 cookie 的值,所以用户会因为 cookie 与配置不匹配而自动注销