【问题标题】:How to prevent displaying the home page after logging out退出后如何防止显示主页
【发布时间】:2015-03-26 19:47:13
【问题描述】:

这是我的 routes.php

<?php
#HomePage
Route::get('/', 'LoginController@home');
Route::post('login', 'LoginController@Login');
Route::group(array('before' => 'auth'), function()
{
Route::get('home', 'HomeController@HomeLayout');
Route::get('logout', 'LoginController@Logout');
});

在退出时我有

   public function Logout()
    {
        Session::flush();
        return Redirect::to('');
    }

一旦我注销,我就会成功重定向到'' 页面,即 localhost/home,因为我的登录控制器中有这个

public function home()
{
    return View::make('login/home');
}

我的问题是,一旦我按下注销并按下后退按钮,我就可以看到 localhost/home,尽管我在 Route::group(array('before' =&gt; 'auth'), function() 中使用过它

我还配置了filters.php

Route::filter('guest', function()
{
    if (Auth::check()) return Redirect::to('/')->with('Message', 'Please Login to get Access');
});

Route::filter('auth', function()
{
    if (Auth::guest())
    {
        if (Request::ajax())
        {
            return Response::make('Unauthorized', 401);
        }
        else
        {
            return Redirect::guest('')->with('Message', 'Please Login to get Access');
        }
    }
});

注意:一旦我刷新它会直接注销,但我什至不想在刷新之前显示主页

如何防止在他们退出后按浏览器的返回按钮后显示主屏幕?

【问题讨论】:

    标签: php authentication laravel laravel-4 laravel-routing


    【解决方案1】:
    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');
    });
    

    routes.php 中添加这些行并检查。

    这将清除cache

    【讨论】:

    • 虽然这个答案是正确的 - 请记住您正在阻止浏览器缓存 - 所以您为此牺牲了性能。
    猜你喜欢
    • 2012-04-15
    • 2023-04-06
    • 2011-10-02
    • 1970-01-01
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    相关资源
    最近更新 更多