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";