通过点击L5中浏览器上的后退按钮,防止退出后退回登录?

时间:2015-04-20 06:05:56

标签: php caching laravel-5

我的问题是,当我已经注销时,我想要做,如果我点击浏览器上的后退按钮,它永远不会返回管理主页。

现在当我点击后退按钮它显示管理员秘密页面,但当我刷新页面然后它回到登录页面。

我解决了它在Laravel 4.2上的filter.php中编写代码

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

但是现在如何通过点击L5中浏览器上的“后退”按钮来阻止退出登录?

2 个答案:

答案 0 :(得分:10)

将此行保留在登录页面的顶部。这将清除缓存并阻止后页(pabel)

<?php echo
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: text/html');?>

答案 1 :(得分:3)

对我有用:

将此javascript代码放在登录页面的末尾,这样您就无法返回,然后一旦系统无法访问之前的页面

 <script>
    window.onload = function () {
        if (typeof history.pushState === "function") {
            history.pushState("jibberish", null, null);
            window.onpopstate = function () {
                history.pushState('newjibberish', null, null);
            };
        } else {
            var ignoreHashChange = true;
            window.onhashchange = function () {
                if (!ignoreHashChange) {
                    ignoreHashChange = true;
                    window.location.hash = Math.random();
                } else {
                    ignoreHashChange = false;   
                }
            };
        }
    }
 </script>