Jump to content

Archived

This topic is now archived and is closed to further replies.

ucichem

Blocking access to Previous Page

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.

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

×

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.