我正在尝试构建一个系统,该系统会给用户一个随机问题,然后通过 POST 将用户的答案和正确答案发送到下一页,而不会向用户显示正确答案是什么。FileB.php
加载时,var_dump($_POST);
读取
array(1) {
["response"]=>
string(32) "Whatever the user's response was"
}
为什么我下面的东西不起作用?为什么ans
post请求没有通过?
文件A.php
<?PHP
function post($data) // from http://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php
{
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n"
, 'method' => 'POST'
, 'content' => http_build_query($data)
),
);
$context = stream_context_create($options);
}
post(array("ans" => "Correct Answer"));
?>
<HTML>
<HEAD>
<TITLE>Form</TITLE>
</HEAD>
<BODY>
<FORM METHOD="post" ACTION="FileB.php">
<LABEL>What is the correct answer? <INPUT TYPE="text" NAME="response"/></LABEL>
</FORM>
文件B.php
<HTML>
<HEAD>
<TITLE>Results</TITLE>
</HEAD>
<BODY>
<?PHP
if ($_POST["ans"] == $_POST["response"])
{
echo "You are correct!";
}
else
{
echo "You're wrong!";
}
?>
</BODY>
</HTML>