我做了一个简短的测验,其中包含4个是/否的问题,我试图做的是如果用户关闭第二个问题时关闭网页,那么当他们重新打开页面时长达30天之后),他们将被带到他们留下的同一个问题。以下是我到目前为止的一些代码。
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 "
}
//Function for showing questions 8 to 15
function showanswer($creature2,$creature3) {
echo "
Yes
No
}
//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 "
}
//Question 2
if ($_GET['yes1']) //If answer to Q1 is yes then display this
{
echo "
{$questions[0][0]}
showquestion(1);
}
//Question 3
if ($_GET['no1'])
{
echo "
{$questions[0][1]}
showquestion(2);
}
//Questions 4 and 5
switch($_GET['answer1']) //If Question 2 is yes, do this
{
case 'Yes': echo "
{$questions[1][0]}
showquestion(3);
break;
case 'No': echo "
{$questions[1][1]}
showquestion(4);
}
//Questions 6 and 7
switch($_GET['answer2']) //If Question 3 is yes, do this
{
case 'Yes': echo "
{$questions[1][2]}
showquestion(5);
break;
case 'No': echo "
{$questions[1][3]}
showquestion(6);
}
//Questions 8 and 9
switch($_GET['answer3'])
{
case 'Yes': echo "
{$questions[2][0]}
showanswer('Eagle','Parrot');
break;
case 'No': echo "
{$questions[2][1]}
showanswer('Ostrich','Turkey_(bird)');
}
//Questions 10 and 11
switch($_GET['answer4'])
{
case 'Yes': echo "
{$questions[2][2]}
showanswer('Grasshopper','Ant');
break;
case 'No': echo "
{$questions[2][3]}
showanswer('Gorilla','Tiger');
}
//Questions 12 and 13
switch($_GET['answer5'])
{
case 'Yes': echo "
{$questions[3][0]}
showanswer('Penguin','Goose');
break;
case 'No': echo "
{$questions[3][1]}
showanswer('Frog','Salamander');
}
//Questions 14 and 15
switch($_GET['answer6'])
{
case 'Yes': echo "
{$questions[3][2]}
showanswer('Octopus','Jellyfish');
break;
case 'No': echo "
{$questions[3][3]}
showanswer('Goldfish','Eel');
}我知道这是可能的,因为我以前见过其他人这样做。测验在这里My Quiz