After session destroy or close browser tab or close browser execute logout using Laravel 5.2
Solution 1
The server does not know if the user has closed the browser window. You need to detect this event via javascript on the client side and notify the server manually.
See this answer: javascript detect browser close tab/close browser
Solution 2
Do this 'expire_on_close' => true
in app/config.php if you want users session to expire or destroy only when the entire browser is closed not the tab.
If only the tab is closed it wont destroy the session except the entire browser is closed.
Comments
-
sandip kakade almost 2 years
In my project I am using session destroy method which very simple way in Laravel 5.2 .
/* |-------------------------------------------------------------------------- | 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' => 10, 'expire_on_close' => true,
Now my question is when session destroy automatically or user close browser tab or close browser that time execute logout query. Is it possible execute logout function all cases?
My logout function
public function logout() { $user = Auth::user()->toArray(); $user1 = ActiveUsers::where("assinedto_id",'=',$user['_id']); $user1 ->delete(); Auth::logout(); return redirect('/login'); }
I want to when session destroy or close browser tab or close browser that time run
logout()
function. Please suggest me. Thanks -
sandip kakade over 7 yearsbut if session is automatically destroy like after 10min destroy that time i want to call function logout(). So how can i call this function after session destroy
-
Matey over 7 yearsSee this answer: stackoverflow.com/questions/11603197/…
-
Chirag over 4 yearsHave you tested this? We tried doing this and actually doesnt work.
-
Digvijay almost 4 years@Chirag After changing any config, you have to run
php artisan config:clear
andphp artisan cache:clear
-
Adam Pery almost 3 yearsActually 'expire_on_close' existing in 'config/session.php'