简体   繁体   English

Symfony 2用户身份验证

[英]Symfony 2 user authentification

in my web site, I implemented user authentification based on the documentation. 在我的网站上,我根据文档实施了用户身份验证。 What I want to know is how to disconnect automatically the user after 15 minutes of inactivity. 我想知道的是,闲置15分钟后如何自动断开用户连接。 Thanks in advance 提前致谢

you can set the session timeout to establish a function like this. 您可以设置会话超时以建立这样的功能。 see How to set expiration time to session in the controller? 请参阅如何在控制器中设置会话的过期时间? this will end the user's session with his first click after 15min of inactivity and redirect him to the login page. 闲置15分钟后,第一次单击将结束用户的会话,并将其重定向到登录页面。

an automated disconnect by eg redirecting to the logout url after 15min of inactivity (by javascript) is also possible. 闲置15分钟后(通过javascript),例如通过重定向到注销网址,也可以实现自动断开连接。

As mentioned here the following snippet should take you to your goal: 如前所述这里下面的代码片段应该带你到你的目标:

$session->start();

if (time() - $session->getMetadataBag()->getCreated() > $maxTime) {
  $session->invalidate();
  throw new SessionExpired(); // redirect to expired session page
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM