Jump to content


Blocking access to Previous Page

  • Please log in to reply
5 replies to this topic

#1 ucichem

  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 01 August 2006 - 05:35 PM

Is there any way to block access to the 'Back' button (the previous page button)?

I am creating an online quiz and want to prevent users from answering a question, getting it wrong, then hitting the back button and trying again.  The users are picking an answer from a series of radio buttons, then hitting submit and are re-directed using php conditionals.


#2 freakus_maximus

  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 01 August 2006 - 05:42 PM

I don't think you can block that.

What you should do is set a session variable for each question to determine if it has been answered already and if it has then dont display the question/radio buttons, etc...give them a message that the question has already been answered.

And of course a link to the next question so they can move on as you intended.

#3 Buyocat

  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 01 August 2006 - 05:45 PM

One way would be to store page urls in an array in the session data.  So at the top of each page you'd do something like...
$self = $_SERVER['PHP_SELF']
if (array_search($self, $_SESSION['previous']))
echo 'You cannot go back...';
} else {
$_SESSION['previous'][] = $self;

Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#4 gerkintrigg

  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 01 August 2006 - 06:08 PM

Buyocat - you beat me to it.

I use something called Not_Here (Defined by me by the way...)

I use it for pages which require members to be logged in. The top include file (which holds the global navigation for the site) has this code in:

<?php // where was I?
		 if ($not_here!='yes'){
Now if it's a page which I don't want the user to ever return to (like a page with only switch statements which re-directs the user to different pages, but has no output) I call the variable $not_here and set it to 'yes' like this:
Whenever I need the user to go back to the last page he was at (in this case a restricted page) he just clicks on one link (made by printing the $_SESSION['where_last'] variable to a href tag) and he goes back to that page. Why not use the back button? It'll take him back to the login page which will then say that there's an error - empty fields... Then it'll take him back to the page where he needs to enter the info, then eventually back to the page that required info, which redirected him to the login page... but he'd need to refresh to get the new session info into that page anyway...

hope that makes sense.
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#5 ucichem

  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 02 August 2006 - 05:28 PM

The globals are turned off on my system.  Anyone know a quick and easy way to turn them on?

#6 spfoonnewb

  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 02 August 2006 - 05:48 PM

If you have root access, just edit your php.ini

If you dont, ask your host. (A shared host most likely wont.)

Its location depends on your CP.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users