[英]Symfony2 - redirect user back after re-login, if logged out because session expired?
In Symfony 2.8, if user's session expires, he'll be logged out and redirected to login page after he makes new request. 在Symfony 2.8中,如果用户的会话到期,则在发出新请求后,他将被注销并重定向到登录页面。
After user logs in again, how can I redirect the user back to the page he wanted to open before he was redirected? 用户再次登录后,如何将用户重定向回他要在重定向之前打开的页面? Or at least to the last page he opened (page, on which session expired)?
还是至少到他打开的最后一页(页面,哪个会话已过期)?
You could let the login action check or there was a referer, and update the security target path. 您可以让登录操作检查或存在引荐来源,然后更新安全目标路径。 Make sure that referrer is safe before you do this ;-)
在执行此操作之前,请确保引荐人是安全的;-)
$yourReferer = $request->headers->get('referer');
$this->container->get('session')->set('_security.main.target_path', $yourReferer);
The login mechanism will use that target_path
after a successful login attempt. 成功尝试登录后,登录机制将使用该
target_path
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.