为PHP测验设置有限的重试次数

时间:2018-04-04 15:49:29

标签: php html5

我目前正在使用PHP运行测验,如果您提出错误的问题,您可以选择返回主页并重新开始或重试问题。但是,在这样做时,您可以无限地尝试猜测答案。有什么方法可以设置它,所以我们说你只能再试一次才能得到正确的答案吗?我一直在试图查明它,坦白说我还没有找到任何关于这个主题的内容。以下是我用来检查答案是否正确的示例代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Answers for Color Quiz</title>
<style>
body{
background: linear-gradient(90deg, #FFFF00, #ffae42, #FFA500,   #ff5349, #FF0000, #c71585 , #EE82EE, #8A2BE2, #0000FF, #0d98ba, #00FF00, #9ACD32);
background-size: 1800% 1800%;

-webkit-animation: rainbow 40s ease infinite;
-z-animation: rainbow 40s ease infinite;
-o-animation: rainbow 40s ease infinite;
animation: rainbow 40s ease infinite;}

@-webkit-keyframes rainbow {
0%{background-position:0% 82%}
50%{background-position:100% 19%}
100%{background-position:0% 82%}
}
@-moz-keyframes rainbow {
0%{background-position:0% 82%}
50%{background-position:100% 19%}
100%{background-position:0% 82%}
}
@-o-keyframes rainbow {
0%{background-position:0% 82%}
50%{background-position:100% 19%}
100%{background-position:0% 82%}
}
@keyframes rainbow { 
0%{background-position:0% 82%}
50%{background-position:100% 19%}
100%{background-position:0% 82%}
}
h1{
font-family:"Times New Roman", Times, serif; 
font-size:10em;
text-align:center;
}
#bodies{
font-family:"Times New Roman", Times, serif; 
font-size:5em;
text-align:center;
}
input[type=text] {
-ms-transform: scale(3); /* IE 9 */
-webkit-transform: scale(3); /* Chrome, Safari, Opera */
transform: scale(3);

}
input[type="submit"] {
-ms-transform: scale(3); /* IE 9 */
-webkit-transform: scale(3); /* Chrome, Safari, Opera */
transform: scale(3);
}
</style>
</head>
<body>
<h1>Color Wheel Quiz </h1><p>
<div id=bodies>
<?php
include('colorquiz.php');
$choice=$_GET['choice'];
$right=@$_GET['right'];
$left=@$_GET['left'];
$which=$_GET['which'];
$correctright=$rightcolors[$choice];
$correctleft=$leftcolors[$choice];
if ($which=='right') {
if (metaphone($left) == metaphone($correctleft)) {
   print("Correct! $correctleft is the capital of $correctright!");
   print("<p><a href='colorquizask.php'>Play again </a>");
   }   
else {
   print("Wrong Study More!<p>\n");
   print("<a href='colorquizask.php'>Back to home </a><p>\n");
  print("OR try again: What is opposite of $correctright on the color   wheel?<br>");
 print("<form action='colorquizcheck.php' method='get'>\n");
 print("<input type='text' name='left'><br>\n");
 print("<input type='hidden' name='right' value=$right>\n");
 print("<input type='hidden' name='which' value=$which>\n");
 print("<input type='hidden' name='choice' value=$choice>\n");
 print("<input type='submit' value='Submit Answer'>");
 print("</form>\n");
}  }
else {
if (metaphone($right) == metaphone($correctright)) {
   print("Correct! The color opposite of $correctright is    $correctleft!");
   $saywhich='false';
   print("<p><a href='colorquizask.php'>Play again </a>");
   }
else {
print("Wrong Study More!<p>\n");
   print("<a href='colorquizask.php'>Back to home </a><p>\n");
  print("OR try again: $correctleft is the opposite of what color?  <br>");
 print("<form action='colorquizcheck.php' method='get'>\n");
print("<input type='text' name='right'><br>\n");
 print("<input type='hidden' name='left' value=$left>\n");
 print("<input type='hidden' name='which' value=$which>\n");
 print("<input type='hidden' name='choice' value=$choice>\n");
 print("<input type='submit' value='Submit Answer'>");
 print("</form>\n");
}  }
?>
</div>
</body>
</html>

整个想法是再给你一个尝试,然后它会打印抱歉不再重试,然后它将链接回主页。

0 个答案:

没有答案