-1

我正在创建一个在线测验系统。假设 question1 的 url 是 /Q/Q1.php ,而 question2 的 url 是 /Q/Q2.php 。我不希望用户在不解决问题 1 的情况下直接跳到 Q2.php 页。我该如何实现呢?

4

2 回答 2

2

您需要存储会话中已回答的问题。这样,您可以检查每个请求的会话,看看他们是否被允许回答这个问题。

session_start(); // always start the session with each request

if (/* question was answered correctly */) {
    $_SESSION['questions'][] = $question_number;
} else {
    /* question was not answered correctly take action here */
}

// To check if they may proceed to the next question

if (in_array($question_number - 1, $_SESSION['questions'])) {
    /* Show the next question */
} else {
    echo "You didn't answer the last question yet!";
}
于 2013-01-19T04:49:52.573 回答
0

您可以按以下方式进行

Q1.php

<html>
<p>What is stack overflow</p>
<form method="post" action="Q2.php">
<input type="radio" name="answer1" value="Website">Website<br>
<input type="radio" name="answer1" value="Software">Software<br>
<input type="submit" value="submit" name="Q1"> 
</form>
</html>

Q2.php

<?php
if($_POST['answer1']==null)
{
    header('Location:Q1.php');
}
else
{
    ?>
    <p>This is question 2</p>
<form method="post" action="Q3.php">
<input type="radio" name="answer2" checked value="Website">Website<br>
<input type="radio" name="answer2" value="Sotware">Software<br>
<input type="submit" value="submit" name="Q1"> 
</form>
<?php
}

?>

希望能帮助到你。

于 2013-01-19T05:08:31.333 回答