简体   繁体   English

如何在Laravel注销后留在同一页面

[英]How to stay on the same page after a logout in Laravel

As the question title suggests, I'm wondering how to set my website up so that the user stays on the same page after a log out. 正如问题标题所示,我想知道如何设置我的网站,以便用户在注销后保持在同一页面上。 In particular, I'm wondering if Laravel provides syntax to do this. 特别是,我想知道Laravel是否提供了这样做的语法。 I'm hoping to use best practice for within Laravel. 我希望在Laravel中使用最佳实践

For example: 例如:

The log in link is displayed at the top of every every page. 登录链接显示在每个页面的顶部。 Bob is logged in and viewing the 'about' page. Bob已登录并正在查看“关于”页面。 Bob clicks 'Log Out.' Bob点击“退出”。 Bob is logged out and redirected back to the about page. Bob已注销并重定向回about页面。

I figured this would be a nice way to do it, since the auth filter can then determine if the page is protected or not and redirect accordingly. 我认为这是一个很好的方法,因为auth过滤器可以确定页面是否受到保护并相应地重定向。

I'M ALSO INTERESTED if you think this is bad practice from a usability standpoint. 如果你认为从可用性的角度来看这是不好的做法,我也很感兴趣。 Most examples I've seen have the logout function redirect to the home page. 我见过的大多数示例都将注销功能重定向到主页。 Is there any reason NOT to stay on the same page? 有什么理由不留在同一页面上吗?

Die you try: return Redirect::back(); 你试试看:返回Redirect :: back(); In your logout route/controller? 在您的注销路线/控制器中?

From a usability standpoint, I think it is a very good idea to send the user back to the page they were on after logging out, provided it is not a protected page. 从可用性的角度来看,我认为将用户退回登录后的页面是一个非常好的主意,前提是它不是受保护的页面。

It is actually quite easy to achieve. 实际上很容易实现。 You need to make your logout link like this: example.com/logout?redir=about.html . 您需要像这样建立注销链接: example.com/logout?redir=about.html

Now, after logging the user, check if $_GET['redir'] exists, and if it does, send them back to that page, other send them to the homepage. 现在,在记录用户之后,检查$_GET['redir']存在,如果存在,则将它们发送回该页面,其他人将它们发送到主页。 After logging out, and before redirecting to the same page, it might be a good idea to show them another page for a few seconds that says 'You've been logged out.' 在注销之后,在重定向到同一页面之前,最好向他们显示另一个页面几秒钟,上面写着“你已经注销了”。

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

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