0

我做了一个包含 4 个是/否问题的简短测验,我想要做的是,如果用户在第二个问题上关闭网页,那么当他们重新打开页面时(最多 30 天后)他们将被带到他们留下的相同问题。下面是我到目前为止得到的一些代码。

<?php
session_set_cookie_params(2592000); //Sets cookie to last for 30 days
session_start();
?>

这是问题的代码

//Variables for functions
 $number;
 $creature2;
 $creature3;
 //Function for showing questions 2 to 7
  function showquestion($number) {

      echo "<div class='questions'><form method ='GET' action='Creatures.php'>
     <input type='submit' name='answer$number' value='Yes' class='buttons' />
     <input type='submit' name='answer$number' value='No' class='buttons' />
     </form></div>";
 }

  //Function for showing questions 8 to 15
  function showanswer($creature2,$creature3) {
      echo "<div class='questions'><form method ='GET' action='Creatures.php'>
     <button type='submit' name='final' value='$creature2' class='buttons'> Yes </button>
     <button type='submit' name='final' value='$creature3' class='buttons'> No </button>
     </form></div>";
 }
//If start button has not been pressed, display nothing
if (!isset($_POST['start'])){

} //If start button has been pressed, display questions
else{ 
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 ($_GET['yes1']) //If answer to Q1 is yes then display this
{
echo "<div class='questions'><p>{$questions[0][0]}</p></div>";
showquestion(1);
}

//Question 3
if ($_GET['no1']) 
{
echo "<div class='questions'><p>{$questions[0][1]}</p></div>"; //If answer to Q1 is no then display this
showquestion(2);
}

//Questions 4 and 5
switch($_GET['answer1']) //If Question 2 is yes, do this
{
case 'Yes': echo "<div class='questions'><p>{$questions[1][0]}</p></div>";
showquestion(3);
break;
case 'No': echo "<div class='questions'><p>{$questions[1][1]}</p></div>";
showquestion(4);
}

//Questions 6 and 7
switch($_GET['answer2']) //If Question 3 is yes, do this
{
case 'Yes': echo "<div class='questions'><p>{$questions[1][2]}</p></div>";
showquestion(5);
break;
case 'No': echo "<div class='questions'><p>{$questions[1][3]}</p></div>";
showquestion(6);
}

//Questions 8 and 9
switch($_GET['answer3']) 
{
case 'Yes': echo "<div class='questions'><p>{$questions[2][0]}</p></div>";
showanswer('Eagle','Parrot');
break;
case 'No': echo "<div class='questions'><p>{$questions[2][1]}</p></div>";
showanswer('Ostrich','Turkey_(bird)');
}

//Questions 10 and 11
switch($_GET['answer4']) 
{
case 'Yes': echo "<div class='questions'><p>{$questions[2][2]}</p></div>";
showanswer('Grasshopper','Ant');
break;
case 'No': echo "<div class='questions'><p>{$questions[2][3]}</p></div>";
showanswer('Gorilla','Tiger');
}

//Questions 12 and 13
switch($_GET['answer5']) 
{
case 'Yes': echo "<div class='questions'><p>{$questions[3][0]}</p></div>";
showanswer('Penguin','Goose');
break;
case 'No': echo "<div class='questions'><p>{$questions[3][1]}</p></div>";
showanswer('Frog','Salamander');
}

//Questions 14 and 15
switch($_GET['answer6']) 
{
case 'Yes': echo "<div class='questions'><p>{$questions[3][2]}</p></div>";
showanswer('Octopus','Jellyfish');
break;
case 'No': echo "<div class='questions'><p>{$questions[3][3]}</p></div>";
showanswer('Goldfish','Eel');
}

我知道这是可能的,因为我以前见过其他人这样做。测验在这里我的测验

4

0 回答 0