-1
我正在創建一個在線測驗系統。假設question1 url爲/Q/Q1.php,而question2 url爲/Q/Q2.php。我不希望用戶直接跳到頁面Q2.php而不解決問題1.我該如何實現這一點?如何通過在php中更改url來檢查頁面跳過
我正在創建一個在線測驗系統。假設question1 url爲/Q/Q1.php,而question2 url爲/Q/Q2.php。我不希望用戶直接跳到頁面Q2.php而不解決問題1.我該如何實現這一點?如何通過在php中更改url來檢查頁面跳過
如下
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
}
?>
希望它可以幫助你可以做到這一點。
您需要存儲會話中已回答的問題。這樣你可以檢查每個請求的會話,看看他們是否被允許回答這個問題。
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!";
}
將最後一頁保存在會話變量或cookie中,並在頁面加載時進行比較。 – Rob
您可以使用會話管理他們的問題索引。 –