I have made a yes/no quiz where the game tries to guess what creature you are thinking of based on these questions, there are only 16 possible answers.
What I am trying to is make it so that if the user closes the site part-way through the quiz then when they return to the quiz they will taken to the same question they left off on. Below is what I have done so far but it doesn't work properly (see for yourself at http://s504518.brunelweb.net/Creatures.php) You must answer yes to the first question and then close the browser as I have only done a session for that question so far. Here is part of the what I have done so far
//These are used for saving the session
$q2 = "<div class='questions'><p>{$questions[0][0]}</p></div>";
$q3 = "<div class='questions'><p>{$questions[0][1]}</p></div>";
$f2 = "<div class='questions'><form method ='GET' action='Creatures.php'>
<input type='submit' name='answer1' value='Yes' class='buttons' />
<input type='submit' name='answer1' value='No' class='buttons' />
</form></div>";
$f3 = "<div class='questions'><form method ='GET' action='Creatures.php'>
<input type='submit' name='answer2' value='Yes' class='buttons' />
<input type='submit' name='answer2' value='No' class='buttons' />
</form></div>";
//If start button has not been pressed, display nothing
if (!isset($_POST['start'])){
} //If start button has been pressed, display questions
else
{
//Display the first question
echo $firstquestion;
echo "<div class='questions'><form method ='GET' action='Creatures.php'>
<input type='submit' name='yes1' value='Yes' class='buttons' />
<input type='submit' name='no1' value='No' class='buttons' />
</form></div>";
}
//Question 2
if (isset($_SESSION['form']))
{
echo $_SESSION['question'];
echo $_SESSION['form'];
}
else{
if ($_GET['yes1']) //If answer to Q1 is yes then display this
{
echo "<div class='questions'><p>{$questions[0][0]}</p></div>";
showquestion(1);
$_SESSION['question'] = $q2;
$_SESSION['form'] = $f2;
}
}
What I am trying to achieve here is, if a session has already been set then display the question and form from that session and if it hasn't display nothing until they click the start button. I'm not sure why it doesn't work properly and any help would be much appreciated.
You need to create a session with session_start(), put this into the first line of php:
session_start();
As php.net tells me, it will also use already generated sessions. Just be shure you have no html-output before starting the session