这是一个非常基本的方法来检查是否给出了正确的答案,并header
用于重定向到另一个页面。
如果用户answer
在您的表单字段中键入单词,那么它将被设置为TRUE
.
如果答案不正确,将显示Sorry, wrong answer.
<?php
if(isset($_POST['submit'])) {
$answer = "answer";
if($_POST['number'] == $answer) {
// echo "Correct";
header("Location: correct.php");
} else {
die("Sorry, wrong answer.");
}
}
?>
使用会话方法:
<?php
session_start();
if (!isset($_SESSION['name'])) {
$_SESSION['name'] = "correct";
}
if(isset($_POST['submit'])) {
$answer = "answer";
if($_POST['number'] == $answer) {
header("Location: correct.php");
} else {
die("Sorry, wrong answer");
}
}
else {
die("You cannot access this page from here.");
}
?>
正确的.php
<?php
session_start();
if (!isset($_SESSION['name'])) {
die("Sorry, session not set.");
}
else {
echo "Correct answer.";
}
?>