【发布时间】:2010-01-25 17:11:08
【问题描述】:
诚然,我对 PHP 的熟练程度不如我希望的那样。我的大部分经验是使用 Wordpress 循环。
我正在尝试创建一个非常简单的测验,其中包含 URL 中正确答案的数量(例如 domaindotcom/?p=3,如果他们到目前为止得到了 3 个正确答案)。
我正在使用以下 PHP 代码来启动它:
<?php
/* Gets current correct answer Count */
$answer_count = $_GET["p"];
/* checks to see if the submitted answer is the same as the correct answer */
if ($_POST["submitted-answer"] == "correct-answer") {
$answer_count++;
}
?>
现在我知道我可以使用链接获得正确的链接:
<a href="link-to-next-question.php/?p=<?php echo $answer_count; ?>">Next Question</a>
但现在我尝试在表单中使用它并被 POST、GET 等弄糊涂了。
这是我的 HTML:
<form name="quiz" action="" method="POST">
<label for="o1"><input type="radio" name="grp" id="o1" value="o1"> Label 1</label>
<label for="o2"><input type="radio" name="grp" id="o2" value="o2"> Label 2</label>
<label for="o3"><input type="radio" name="grp" id="o3" value="o3"> Label 3</label>
<input type="submit" value="Next Question" class="btn">
</form>
如何选择正确的答案(安全性不重要,这只是一个有趣的测验),然后将它们发送到下一个 URL,同时在创建 URL 之前将增量添加到 $answer_count?
【问题讨论】:
-
如果我在网址中手动增加
p欺骗我下一个问题怎么办? -
那么你在测验结束时不会收到金星
-
只是为了好玩。如果他们想让 url p=100000,那很好。没有奖品,不涉及金钱,没有广告,他们只是因为得到一个愚蠢的结果而输了。