问题描述
在我的项目中,我使用会话破坏方法,这在Laravel 5.2中非常简单.
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?
我的注销功能
public function logout()
{
$user = Auth::user()->toArray();
$user1 = ActiveUsers::where("assinedto_id",'=',$user['_id']);
$user1 ->delete();
Auth::logout();
return redirect('/login');
}
我想在会话销毁或关闭浏览器选项卡或关闭浏览器时运行 logout()
函数.请给我建议.谢谢
I want to when session destroy or close browser tab or close browser that time run logout()
function. Please suggest me. Thanks
推荐答案
服务器不知道用户是否已关闭浏览器窗口.您需要通过客户端上的javascript检测到此事件,并手动通知服务器.
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检测浏览器关闭标签/关闭浏览器
这篇关于会话销毁或关闭浏览器选项卡或关闭浏览器后,使用Laravel 5.2执行注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!