オンラインクイズシステムを作成しています。質問1のURLが/Q/Q1.phpで、質問2のURLが/Q/Q2.phpであるとします。質問1を解決せずに、ユーザーがQ2.phpページに直接スキップすることを望まない。これを実装するにはどうすればよいですか?
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 に答える