Prevent Browser's Back Button Login After Logout in Laravel 5

Prevent Browser's Back Button Login After Logout in Laravel 5

When the user clicks the back button they're not actually logged in, its just the browser rendering what it has cached from previous page views. The user won't be able to navigate or interact with anything that requires them to be logged in because, to your application on the server, they're not authenticated.

When the user clicks the back button you have no control over that as it doesn't make a request to the server.

Using the back button, the only content they'll be able to view is that what they have already visited whilst logged in. If they try to access anything new, they'll make a new request to your application, your middleware will trigger and redirect them to the login page.

I guess if you really wanted to stop this behavior you could use some JavaScript and such to send an ajax request and check if the user is logged in that way, but quite useless from a security point of view.

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

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

Laravel logout, hittin gthe back button send s me back into the app, how do I prevent this

If you just want to prevent the back button being used, and don't actually care that the user can hold the back button and go to earlier pages, then the following disables the back button.

(of course you can use both disable cache and disable back button)

Create a new 'Logged out' view

This is optional but means you can add the javascript without worrying about affecting any other functionality.

@extends('layouts.app',[$title='Logout | '])

@section('content')
<div class="container mx-auto">
<div class="flex flex-wrap justify-center">
<div class="w-full max-w-md">

<h1 class="text-2xl text-gray-700 text-center">You have been successfully logged out</h1>

<p class='mt-8 text-xl text-indigo-800 text-center underline'><a href="{{ route('login') }}">Login?</a></p>

<script type="text/javascript">
history.pushState(null, null, `{{ route('logout') }}`);
window.addEventListener('popstate', function () {
history.pushState(null, null, `{{ route('logout') }}`);
});
</script>

</div>
</div>
</div>
@endsection

Create a route to display the logout page


Route::view('/logout','auth.logout')->name('logout');

Modify the login controller to go to the Logout view

Add the following code somewhere inside App\Http\Controllers\Auth\LoginController.php

    private function loggedOut($request)
{
return redirect(route('logout'));
}


Related Topics



Leave a reply



Submit