laravel 5毁灭会议

时间:2016-10-31 12:59:21

标签: php laravel

我有一个laravel项目,当我从用户注销时,我会进入登录屏幕,但当回到浏览器中的上一页时,即使我已经注销,我也可以访问主页。我该如何解决?

AuthController.php

  public function logout()
{
  \Auth::logout();
  \Session::flush();
  return redirect()->route('login');
}
}

UsersController.php(返回主视图的home函数)

public function home()
{
  if (\Auth::user())
  {
    return view('users.home');
  }
    return redirect()->route('login');
}

web.php(路线)

Route::get('/home', ['middleware' => 'auth', 'as' => 'home','uses' => 'UsersController@home']);

3 个答案:

答案 0 :(得分:0)

问题是后退按钮不会从服务器请求任何内容。它只是从缓存中加载页面的最后一个已知状态。

您可以使用这一点JavaScript来清除浏览器的后退按钮历史记录:

 history.go(-history.length);   //Go to the first page in the back history.
 window.location.href = '/login'; // Overwrite it with the page to actually go to.

当然,这也可能会使用户失去他们的浏览会话历史记录。

可能有效的替代方法(虽然我还没试过)是告诉浏览器不要通过在这些页面中设置以下标题来缓存需要登录的页面:

header("Cache-Control", "no-cache, no-store, must-revalidate");

但是,这会阻止任何可能对性能产生影响的页面缓存。

答案 1 :(得分:0)

在您的登录页面中输入mount ActionCable.server => '/cable'。这将清除缓存并阻止后页。

<head>

答案 2 :(得分:0)

在您的退出功能中,重定向如下:

return redirect()->to(Url::previous());

现在,当您单击后退按钮时,不再缓存上一页,您只需再次登录页面。

相关问题