会话超时后,如何在Symfony中自动重定向用户? [英] How to auto redirect a user in Symfony after a session time out?

查看:100
本文介绍了会话超时后,如何在Symfony中自动重定向用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一定秒数后强制超时,但是即使注销成功,我仍试图实现对无法实现的URL的自动重定向.有任何想法吗?

I am trying to force a time out after a certain number of seconds however even though the logout works, I am trying to implement a auto redirect to a URL which I am unable to implement. Any ideas?

我正在遵循给出的示例(获得最多投票的答案):

I am following the example given on (the answer with the most votes): How to log users off automatically after a period of inactivity?

推荐答案

该指南仅在您再次向服务器发出请求后将您注销.这意味着您当前所在的页面可能会永远保持打开状态.

That guide will only log you out after you make another request to the server. Meaning the page you are on currently could remain open forever.

在给定时间后将请求强制发送到服务器将非常容易.您可以在模板中添加元刷新:

It would be pretty easy to force a request to the server after a given time. In your template you can add a meta refresh:

<meta http-equiv="refresh" content="300">

将此内容放在html的标头部分中,将在5分钟后重新加载页面.该数字以秒为单位.

Putting this in your header section of your html will reload the page after 5 minutes. The number is in seconds.

然后在SessionIdleHandler类中,您只需将响应更改为重定向到所需的位置即可.

And then in the SessionIdleHandler class you would just change the response to redirect where you wanted.

来自:

$event->setResponse(new RedirectResponse($this->router->generate('fos_user_security_login')));

收件人:

$event->setResponse(new RedirectResponse($this->router->generate('my_bundle.my_route')));

这篇关于会话超时后,如何在Symfony中自动重定向用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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