I'm trying to build a system that will give a user a random question, then send the user's answer and the correct answer to the next page via POST, without ever showing the user what the correct answer is. When FileB.php
loads, var_dump($_POST);
reads
array(1) {
["response"]=>
string(32) "Whatever the user's response was"
}
Why doesn't what I have below work? Why isn't the ans
post request going through?
FileA.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>
FileB.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>