当注销一个用户会话时::flush()方法无法工作


when logouting a user session::flush() laravels wont work

我正在使用laravel来构建一个具有登录身份验证的网站,当用户注销时,他们仍然可以单击浏览器的后退按钮并吹。他们回来了。所以这里是我的代码,我使用session::flush删除会话,但它不会工作。

这是我的代码

公共函数signout(){

    Session::flush();
    Auth::logout(); 
    return Redirect::action('ViewController@signin');
}

通常当用户在浏览器上点击"返回"时,他们的浏览器只是显示一个缓存版本的页面。他们不应该能够与页面进行实际交互(例如提交表单)或做任何需要向服务器发出新请求的事情,而服务器不会响应他们已注销

使用过滤器可以解决这个问题。(我还没有找到任何其他解决方案)首先,在filters.php中添加以下代码:

Route::filter('no-cache',function($route, $request, $response){
    $response->header("Cache-Control","no-cache,no-store, must-revalidate");
    $response->header("Pragma", "no-cache"); //HTTP 1.0
    $response->header("Expires"," Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
});

然后将此过滤器附加到路由或控制器上。我将它附加到控制器的construct函数中,像这样:

public function __construct() {
        $this->beforeFilter('csrf',array('on' => 'post'));
        $this->afterFilter("no-cache", ["only"=>"getDashboard"]);
    }