在Laravel中检查会话超时 [英] Check for Session timeout in Laravel

查看:355
本文介绍了在Laravel中检查会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否有人知道如何在Laravel中检查会话超时.

I was just wondering if anyone knew how to check for session timeout in Laravel.

您可以检查会话中是否有特定项目:

You can check whether the session has a specific item:

if (Session::has('name'))
{
     $name = Session::get('name');
}

但是您无法检查会话是否已过期.太好了,这样我就可以更具体地向用户报告. 您的会话已超时,请重新开始."

But you can't check whether the session has expired. It would be nice so that I can report back to the user in a more specific way. "Your session has timed out, please start again."

有什么想法吗?

推荐答案

只需使用与会话类本身相同的逻辑即可.

Just use the same logic as the session class itself.

if ((time() - Session::activity()) > (Config::get('session.lifetime') * 60))
{
   // Session expired
}

将其放在之前"过滤器中-它将在每个请求上运行.

Place this in your 'before' filter - and it will run on every request.

这篇关于在Laravel中检查会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆