ucichem Posted August 1, 2006 Share Posted August 1, 2006 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 https://forums.phpfreaks.com/topic/16227-blocking-access-to-previous-page/ Share on other sites More sharing options...
freakus_maximus Posted August 1, 2006 Share Posted August 1, 2006 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 https://forums.phpfreaks.com/topic/16227-blocking-access-to-previous-page/#findComment-67190 Share on other sites More sharing options...
Buyocat Posted August 1, 2006 Share Posted August 1, 2006 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 https://forums.phpfreaks.com/topic/16227-blocking-access-to-previous-page/#findComment-67191 Share on other sites More sharing options...
gerkintrigg Posted August 1, 2006 Share Posted August 1, 2006 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 https://forums.phpfreaks.com/topic/16227-blocking-access-to-previous-page/#findComment-67206 Share on other sites More sharing options...
ucichem Posted August 2, 2006 Author Share Posted August 2, 2006 The globals are turned off on my system. Anyone know a quick and easy way to turn them on? Link to comment https://forums.phpfreaks.com/topic/16227-blocking-access-to-previous-page/#findComment-67961 Share on other sites More sharing options...
spfoonnewb Posted August 2, 2006 Share Posted August 2, 2006 If you have root access, just edit your php.iniIf you dont, ask your host. (A shared host most likely wont.)Its location depends on your CP. Link to comment https://forums.phpfreaks.com/topic/16227-blocking-access-to-previous-page/#findComment-67985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.