为什么在laravel中按下浏览器的后退按钮时过滤器不起作用?

TuG*_*llo 6 php browser authentication laravel laravel-4

我想要输入一个帐户,然后调用数据验证的控制器,然后使用身份验证方法保存

    public function doLogin(){
    $rules = array(
                    'email' => 'required|email',
                    'password' => 'required'
                    );

    $validator = Validator::make(Input::all(), $rules);
    //dd(Input::all());

    if($validator->fails()){
        return Redirect::to('usuarios')->withErrors($validator)->withInput(Input::except('password'));
    }else{

        $userdata = array(
            'email' => Input::get('email'),
            'password' => Input::get('password')
            );

        if(Auth::attempt($userdata)){
            return View::make('principal');
        }else{

            return Redirect::to('usuarios');
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

我也有退出会话的功能

Route::get('usuarios/logout', function(){
        Auth::logout();
        return Redirect::to('usuarios'); //login page
})->before('auth');
Run Code Online (Sandbox Code Playgroud)

问题是,当我按下浏览器的后退按钮时,我可以毫无问题地使用应用程序但没有身份验证.

路线

Route::get('usuarios', function(){
return View::make('login');
})->before('guest');

Route::get('usuarios/view', function(){
    $usuarios = Usuario::paginate(5);
    return View::make('viewusuario', array('usuarios' => $usuarios));
})->before('auth');

Route::get('usuario/create', function(){
    return View::make('formusuario');
})->before('auth');
Run Code Online (Sandbox Code Playgroud)

过滤

Route::filter('auth', function()
{
    if (Auth::guest()) return Redirect::guest('usuarios'); //login page
});
Route::filter('guest', function()
{
    if (Auth::check()){
        return View::make('principal'); //home page     
    }
});
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

Rub*_*zzo 6

问题与浏览器缓存有关,而与Laravel无关.

要处理浏览器缓存,您可以在其中一个启动文件服务提供程序中使用以下代码:

App::after(function($request, $response)
{
    $response->headers->set('Cache-Control','nocache, no-store, max-age=0, must-revalidate');
    $response->headers->set('Pragma','no-cache');
    $response->headers->set('Expires','Fri, 01 Jan 1990 00:00:00 GMT');
});
Run Code Online (Sandbox Code Playgroud)

这里我们只是使用应用程序事件修改Laravel中的每个响应.


有人说这适用于所有网页浏览器但不适用于IE浏览器.因此,对于IE,您应该在布局中添加一堆元标记:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="cache-control" content="must-revalidate" />
<meta http-equiv="expires"       content="0" />
<meta http-equiv="expires"       content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma"        content="no-cache" />
Run Code Online (Sandbox Code Playgroud)