In this post, I would like to share a simple Laravel5 Middleware which prevents going back to the previous protected page after Logout by hitting the back button on your Browser.
When you hit the browser back button after logout, it will take you to the original page instead of redirecting to login page. It should redirect to the login page, isn’t it? Here I am gonna share a Middleware which will fix this issue.
Let’s start –
Create a middleware by issuing artisan command from your terminal –
Laravel Prevent Browser back button
Above command will generate a middleware class called
app/http/middleware. Open that file and add response header configurations as shown below.
\app\Http\Kernel.php file, add our custom
ValidateBackHistory middleware in route middleware’s array.
To use this middleware you just need to call
validateBackHistory middleware for routes which require user authentication.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.