Matt
Matt

Reputation: 367

Laravel 5 Destroy all user sessions and force logout

Is there a way to destroy all sessions? I need to logout all users and wondering if this is possible with astrisan?

Thank you!

Upvotes: 5

Views: 7361

Answers (3)

Tjodalv
Tjodalv

Reputation: 370

I know that I come little too late to the party but the easiest method to destroy all existing sessions is to change session cookie name. That way all sessions will be lost for existing users no matter what session storage you use and it won't affect anything else except your sessions.

In your .env file change or add this line:

SESSION_COOKIE="your_new_session_cookie_name"

Instead of "your_new_session_cookie" you can put anything you want as long it is different from the previous value. By default if this variable is not set laravel will use slugified version of "{APP_NAME}"_session" for session cookie name or "laravel_session" if APP_NAME variable is not defined.

Upvotes: 2

Mahdi Youseftabar
Mahdi Youseftabar

Reputation: 2352

it's really depend on with session drive you picked.

  • if you using file drive you can delete storage/framework/sessions path
  • if you using database drive you can delete all rows of session table,
  • if you using redis driver and also your cache driver is redis , you can run php artisan cache:clear

for any other driver you can do that like others.

Upvotes: 11

hasusuf
hasusuf

Reputation: 1589

You can do that by deleting all files under this path

storage/framework/sessions

Upvotes: 2

Related Questions