Answer the question
In order to leave comments, you need to log in
How to clear session in laravel?
This is not about cleaning your session (only this is described in the docks how to do it), but about deleting someone else's session.
That is, how to clean the session by id and not by the current user?
Answer the question
In order to leave comments, you need to log in
In general, I lied, there is an opportunity to do this by standard means (I didn’t wake up while writing the first message).
In Laravel, all session drivers implement SessionHandlerInterface .
You can get the handler with:
Get the current session ID with:
So we need to do the following:
- When a user logs in, get his session ID and store it in the database (for example, add a sesison_id field to the users table).
- When an admin needs to log out a user, you just need to call:
$user = // получаем юзера;
session()->getHandler()->destroy($user->session_id);
Delete the session file if the session is stored in files, if it is in the database, then delete it from the database.
<?php
$pathFile = rtrim(ini_get('session.save_path'),'/').'/' . $sessionId;
if(file_exists($pathFile)){
echo "File exists!";
//unlink($pathFile);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question