Laravel 会话自动到期时注销
Logout on automatic expiration of session in Laravel
如何在 Laravel 会话自动到期时调用注销?我已经在 session.php
中添加了这个
'lifetime' => 10,
'expire_on_close' => true,
您应该尝试以下解决方案。
Use Auth;
public function logout(Request $request) {
Auth::logout();
return redirect('/login');
}
使用 JS 处理 -(在我的项目中工作正常)
/*
* this script is for manage the logout of timeout
* if user is inactive for 15 min
* he will be logout :
*
* */
var logout = 'Are you sure to logout?';
var timeout;
var url = ''; // route path;
document.onmousemove = function(){
clearTimeout(timeout);
timeout = setTimeout(function () {
var confirmstatus = confirm( logout );
if(confirmstatus === true) {
var redirect = $.ajax({
cache: false,
url: url,
type: "GET",
headers: {
'X-CSRF-TOKEN': window.project.csrfToken
},
contentType: false,
processData: false,
success: function (response) {
window.location.href = url;
}
});
}
}, 60000*15);
};
</script>
如何在 Laravel 会话自动到期时调用注销?我已经在 session.php
中添加了这个'lifetime' => 10,
'expire_on_close' => true,
您应该尝试以下解决方案。
Use Auth;
public function logout(Request $request) {
Auth::logout();
return redirect('/login');
}
使用 JS 处理 -(在我的项目中工作正常)
/*
* this script is for manage the logout of timeout
* if user is inactive for 15 min
* he will be logout :
*
* */
var logout = 'Are you sure to logout?';
var timeout;
var url = ''; // route path;
document.onmousemove = function(){
clearTimeout(timeout);
timeout = setTimeout(function () {
var confirmstatus = confirm( logout );
if(confirmstatus === true) {
var redirect = $.ajax({
cache: false,
url: url,
type: "GET",
headers: {
'X-CSRF-TOKEN': window.project.csrfToken
},
contentType: false,
processData: false,
success: function (response) {
window.location.href = url;
}
});
}
}, 60000*15);
};
</script>