duanpo8329 2019-07-31 10:55
浏览 116
已采纳

Laravel:会议在注册表开放时到期

I have have a web app which is waiting for users on a laptop in kiosk mode. Sometimes, registration fails and users get an error screen - I think it's 419 Session Expired.

So I assume two hours after the login screen loads, the session expires (I kept the default of 120 minutes in config/session.php) and Laravel does not accept any request from that page.

How should I deal with this? I know how to make a page reload every 110 minutes or so using JS, but then I'd have to check the registration form is being filled out at this moment. This does not feel like a clean solution to me.

Is there any alternative, such as a mechanism to make Laravel less strict when a request comes from the register or login pages?

  • 写回答

3条回答 默认 最新

  • duanchen6423 2019-07-31 12:00
    关注

    As mentioned, the simplest solution is usually to extend the session expiration time from the default of 2 hours (which is very short).

    If longer sessions are not desirable, another option is to keep the session alive for as long as the browser page is open by using javascript.

    Add a route in routes/web.php:

    Route::post('/keep-alive', function () {
        return response()->json(['ok' => true]);
    });
    

    And then ping this route periodically with javascript:

    setInterval(() => {
        axios.post('/keep-alive')
            .then(() => {})
            .catch(() => {})
    }, 600000)
    

    (I used axios to make the POST request because it's included with a default Laravel install, but you can use anything to make the request.)

    Since the request passes through the web middleware group, the session middleware should be run and keep the session alive. If the browser page is closed, the computer is put to sleep, etc., then the session will still expire normally after the configured time has elapsed.

    You can also check for session expiration responses from the javascript call and refresh the page if one is detected. This case is most likely to occur if the computer resumes operation from a sleeping state.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么