Disable back button in browser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Disable back button in browser

Post by sanju »

Hi all,

I am doing a online exam application. I want t ot disable the back option.. in browser or backspase button.. etc how can I accomplish that .can any one help??

Regards
Sanju
silenceghost
Forum Newbie
Posts: 22
Joined: Sun Oct 19, 2008 3:25 am

Re: Disable back button in browser

Post by silenceghost »

I used to do serverside validation for disabling the back button in the browser by setting
$_SESSION['var'] on top of the code

if this var is set
then forward the page or redirect to the forward page
$_SESSION['VAR']=true;

NOTE:while redirecting make sure you have preserved you get and post variable
if page is refreshed then it will not work because var is being already set you have to avoid being refresh rest are validation

Code: Select all

 
There are client side validation also for which you can use but i don't simply like that
function func1()
{
  setTimeout("func2()", 10);
}
 
function func2()
{
  try {
    history.forward();
  } catch (e) {
  }
  setTimeout("func2()", 400);
}
 
call func1 on onLoad.
I hope that if there was some method to clear the histroy.back()
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Disable back button in browser

Post by pickle »

You can't disable the back button. You can open a new window that doesn't have a back button, but there are other ways to go back. If you're doing any server-side checks, make sure the client is actually requesting a new page every time by turning of caching. Otherwise, the client will just load the page from their cache.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply