How to auto redirect a user in Symfony after a session time out?

前端 未结 1 433
一生所求
一生所求 2020-12-19 18:58

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 t

相关标签:
1条回答
  • 2020-12-19 19:27

    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">
    

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

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

    from:

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

    to:

    $event->setResponse(new RedirectResponse($this->router->generate('my_bundle.my_route')));
    
    0 讨论(0)
提交回复
热议问题