I am trying to use random numbers to authenticate users to prevent robot attacks. I have experimented with the following snippet for one whole day but for the life of me I can't figure out what is going wrong because the variable $_SESSION['number'] is getting passed from session to session but the other isn't:
<?php
session_start();
//Generating two random numbers between 0 and 9
srand(time());
for ($i=0; $i < 2; $i++)
{
$random = (rand()%9);
$slot[] = $random;
}
$numberone = $slot[0];
$numbertwo = $slot[1];
//Displaying the challenge question on the screen
echo "The challenge question is $numberone + $numbertwo = ";
$number = $numberone+$numbertwo;
//Storing the challenge answer in a session variable for validation in the next page.
// This number is getting stored and is being passed along
$_SESSION['number']=$number;
//Gathering user response from the form for comparing with challenge answer
$answer = $_POST['Answer'];
//This variable is not getting passed from one session to another. FRUSTRATING!!!
$_SESSION['answer'] = $answer;
?>
Please HELP!! It is so frustrating.......
<?php
session_start();
//Generating two random numbers between 0 and 9
srand(time());
for ($i=0; $i < 2; $i++)
{
$random = (rand()%9);
$slot[] = $random;
}
$numberone = $slot[0];
$numbertwo = $slot[1];
//Displaying the challenge question on the screen
echo "The challenge question is $numberone + $numbertwo = ";
$number = $numberone+$numbertwo;
//Storing the challenge answer in a session variable for validation in the next page.
// This number is getting stored and is being passed along
$_SESSION['number']=$number;
//Gathering user response from the form for comparing with challenge answer
$answer = $_POST['Answer'];
//This variable is not getting passed from one session to another. FRUSTRATING!!!
$_SESSION['answer'] = $answer;
?>
Please HELP!! It is so frustrating.......
Comment