Hi all,
I've created a questionnaire that consists of few pages, on each page a user is asked a question and given 2-5 possible answers and required to select one. Then a new link for the next page appears for the user to click on to move to the next page. Each answer has a score attached to it and a running total of all scores is kept and shown to the user at the end.

My question is that how can I stop a user, say, from going back to page 1 from page 2 using the back button. I believe there is something in php that can be set to stop the user going back and choosing a different answer.

Any help much appreciated.

--

    it is hard to control the 'back' button on the browser. you could create a session that tracks what page they should be along with the answers they already selected. if they try to go back and resubmit your page will know that the queestion was already answered.

      for IE (and maybe other new browsers) you can create a little javascript that jumps them forward when they hit back:

      function noBack() {
      	if(history.length>0) {
      	//alert('Please use navigational links (Inbox, Cancel) instead of the browser back button.');
      	history.go(+1)
      	}
      }
      

      and in the <body> tag of the page you can add

      onLoad="JavaScript:noBack();"

      HTH
      -Dave

        Heh, calling IE a "new" browser ... heh heh

        It's too easy to disable Javascript; but (I'm presuming you're storing the results from each page in session variables) you can include a variable to record what page they're on. When they submit a page, update the variable to record that they've gone on to the next page. (You should be able to identify which page is being submitted based on the form's contents.) If they try to submit a page they've already submitted, ignore it and just serve up the page they should be on.

        So when the variable is 1, then it means they're only just starting. Display page 1. When you receive that form, set the variable to 2 and display page 2. If they try submitting page 1 again, you'll know something is dodgy because they're supposed to be on page 2. Ignore what they'e just submitted and display page 2 (perhaps with a message saying they they tried going backwards).

          Thanks all,
          I'll probably try combination of solutions suggested by Weedpacket and vt_dave.

          --

            Instead of making multiple pages put everything on one page and dynamically change the page based how many times they've clicked the submit button.... Every time they click it add 1 to your session variable..if the variable = 3 then display what should be on page 3. Even if they use the back button the page will still show page 3. That way it would be impossible for them to go backwards.

              DOING THIS EVEN IF THE USER PRESS BACK HE WILL NEVER SEE THE CONTENTS OF THAT PREVIOUS PAGE AND HE WILL BE REDIRECT IMMEDIATELY TO THE PAGE HE IS SUPPOSED TO BE, I USE THIS METHOD IN MY WEBSITE AND IT WORKS PERFECTLY.
              This is what you have to do:
              Let's assume you have 3 pages.
              Page1 has question # 1 & its possible answers & a submit button.
              Page2 has question # 2 & its possible answers & a submit button.
              Page3 you calculate the results.

              You need a function that we will call correctpage and you need to include it at the beginning of every page after the session_start.
              function correctpage()
              {
              switch($_SESSION['page'])
              {
              case 1:
              if($page=="page1") return(1);
              else header("Location: page1.php")
              break;
              case 2:
              if($page=="page2") return(1);
              else header("Location: page2.php")
              break;

              case 3:
              if($page=="page3") return(1);
              else header("Location: page3.php")
              break;

              case 4:
              if($page=="page4") return(1);
              else header("Location: page4.php")
              break;
              } //END OF SWITCH
              } //END OF FUNCTION

              Page 1 will look like this:
              session_start(); correctpage();
              $_SESSION['page']=1;
              <form action=page2.php method=post>
              //PRINT YOUR QUESTION AND POSSIBLE ANSWERS
              </form>

              Page 2 will look like this:
              session_start(); correctpage();
              $SESSION['page']=2;
              $
              SESSION['answerenteredforQ1']=$_POST['answerenteredforQ1'];
              <form action=page3.php method=post>
              //PRINT YOUR QUESTION AND POSSIBLE ANSWERS
              </form>

              Page 3 will look like this:
              session_start(); correctpage();
              $SESSION['page']=3;
              $
              SESSION['answerenteredforQ2']=$POST['answerenteredforQ2'];
              if($
              SESSION['score']==NULL)
              {
              if($SESSION['answerenteredforQ1']=="acceptedanswer1") $A=1;

              if($
              SESSION['answerenteredforQ2']=="acceptedanswer2")
              $A=2;
              $_SESSION['score']=$A1+$A2;
              }

              Page 4 will look like this:
              session_start(); correctpage();
              $_SESSION['page']=4;
              echo "THANKS FOR ANSWERING OUR QUESTIONS";

                Write a Reply...