Today, We want to share with you how to disable back button in php?.In this post we will show you how to handle browser back button in jQuery, hear for how to handle browser back button in javascript? we will give you demo and example for implement.In this post, we will learn about Disable browser back button using jquery with an example.
How to disable browser back button using Jquery?
I can use window.history.pushState for restrict back button of browser in jquery or JavaScript. i can disable back button in browser using jquery in php source code or any mvc framework like PHP OOP, laravel, codeigniter or many more.
stop the browser back button using JavaScript
Example 1:
<!DOCTYPE html> <html> <head> <title>How to disable browser back button using Jquery? - www.pakainfo.com</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> </head> <body> <button>click on browser back button</button> </body> <script type="text/javascript"> $(document).ready(function() { window.history.pushState(null, "", window.location.href); window.onpopstate = function() { window.history.pushState(null, "", window.location.href); }; }); </script> </html>
Example 2: Disable Back Button in Browser using JavaScript
<SCRIPT type="text/javascript"> window.history.forward(); function noBack() { window.history.forward(); } </SCRIPT> </HEAD> <BODY onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
Warn User if Back is Pressed
window.onbeforeunload = function() { return "You work will be lost."; };
how to disable back and forward button of browser in php?
login.php page :
<?php if (isset($_POST['uname'], $_POST['pwd'], $_POST['type'])) { $Username = $_POST['uname']; $Password = $_POST['pwd']; $User_Type=$_POST['type']; if (!(empty($Username) || empty($Password) || empty($User_Type))) { $model = new UsersModel(); $rowsCount = $model->checkUser($Username,$Password,$User_Type); if ($rowsCount!=0) { $_SESSION['user'] = $Username; header("Location:LoginViewController.php"); } else { echo 'Bad user'; } } else { echo 'Please, fill all inputs'; } } else { echo 'Bad form sent'; } ?> <form name="f1" method="POST" action="" > // inputs </form>
LoginViewController.php :
<?php header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); if (!isset($_SESSION['user'])) { header('Location: login.php'); exit(); } echo 'You have successfully logged as '.$_SESSION['user'] ?>
logout.php :
<?php session_start(); session_destroy(); $_SESSION = array(); header("location: login.php"); ?>
I hope you get an idea about Restrict or Disable Browser Back Button.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.