为什么当浏览器的后退按钮在laravel pssed $ P $过滤器不起作用? [英] Why the filter does not work when the back button of the browser is pressed in laravel?

查看:409
本文介绍了为什么当浏览器的后退按钮在laravel pssed $ P $过滤器不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个观点,进入一个帐户,然后叫对数据进行验证,然后保存验证方法

I have a view to enter an account, then called the controller where the data is validated and are then saved with the method of authentication

    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');
        }

    }
}

我也有退出会话功能

I also have the function to exit the session

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

问题是,当我preSS浏览器的后退按钮,我可以没有任何问题的应用程序,但没有身份验证中使用。

The problem is that when I press the back button of the browser, I can use without problems the application but without the authentication.

路线

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');

过滤器

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     
    }
});

我怎样才能解决这个问题?

How can I fix it?

推荐答案

这个问题涉及到的浏览器缓存的,没有Laravel。

The problem is related to browser cache, not Laravel.

要处理浏览器缓存,你可以使用下面的code在你的启动文件中的一个的或在的服务提供商的:

To handle browser cache you can use the following code in one of your start files or in a service provider:

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');
});

在这里,我们只是修改每个反应中Laravel使用应用程序事件的。

有人说,这适用于所有的Web浏览器而不是IE浏览器。因此,对于IE浏览器,你应该添加了一堆的meta标签到您的布局:

Some people said that this works for all web browser but not for IE. So for IE, you should add a bunch of meta tags to your layout:

<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" />

这篇关于为什么当浏览器的后退按钮在laravel pssed $ P $过滤器不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆