php - Prevent Back Login After Logout by hitting the Back button on Browser in L5?

623

My problem is I want to do when I already logout, If I click back button on browser it never back admin home page.

Now when I click back button It show admin secret pages, But when I refresh the page then It back to login page.

I solved it write the code in filter.php on Laravel 4.2

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

But Now how can I do Prevent Back Login After Logout by hitting the Back button on Browser in L5?

644

Answer

Solution:

Keep this line in top of the login page.That will clear cache and prevent back page(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');?>
482

Answer

Solution:

that work for me:

Put this javascript code at the end of your login page, with this you can not go back and then once outside the system can not reach the previous pages

 <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>
893

Answer

Solution:

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

People are also looking for solutions to the problem: javascript - Jqgrid subgrid not expanding on first load

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.