Jump to content

Blocking access to Previous Page


ucichem

Recommended Posts

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.

Thanks.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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...
[code]
session_start();
$self = $_SERVER['PHP_SELF']
if (array_search($self, $_SESSION['previous']))
{
echo 'You cannot go back...';
exit;
} else {
$_SESSION['previous'][] = $self;
}
[/code]
Link to comment
Share on other sites

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:

[code]<?php // where was I?
if ($not_here!='yes'){
$_SESSION['where_last']=$_SERVER['REQUEST_URI'];
}?>[/code]
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:
[code]$not_here='yes';[/code]
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.