在会话销毁或关闭浏览器选项卡或关闭浏览器后,使用 Laravel 5.2 执行注销
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39408639/
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
After session destroy or close browser tab or close browser execute logout using Laravel 5.2
提问by sandip kakade
In my project I am using session destroy method which very simple way in Laravel 5.2 .
在我的项目中,我使用的是 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
我想当会话销毁或关闭浏览器选项卡或关闭浏览器时运行logout()
功能。请建议我。谢谢
回答by Matey
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.
服务器不知道用户是否关闭了浏览器窗口。您需要在客户端通过 javascript 检测此事件并手动通知服务器。
See this answer: javascript detect browser close tab/close browser
看到这个答案:javascript检测浏览器关闭标签/关闭浏览器
回答by Manojkiran.A
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.
'expire_on_close' => true
如果您希望用户会话仅在整个浏览器关闭而不是选项卡关闭时才过期或销毁,请在 app/config.php 中执行此操作。如果仅关闭选项卡,它不会破坏会话,除非关闭整个浏览器。