Well I had a guessing game in mind and I figured I'd do this:
Generate a random number once.
Assign it to a variable.
Get input from a user via form.
Store this input in a variable and check it vs the random number.
Have a final variable that holds which "Guess Number" it is (how many guesses the user has made thus far).
However, I just ran into a problem that stumped me. How can I pass this information on throughout the game? I originally planned to do it like this:
You go to the game file and make a guess. If you are wrong, the file increments the "Guess Number" variable and sends both the "Guess Number" value and the "Magic Number" value to itself, using this as a way to keep the numbers consistent.
However, it just occured to me that the user will be able to see the "Magic Number" in the URL then.
Therefore, I do not know how to pass the number and the guess number on through multiple steps.
Can someone please enlighten me? Thanks.
Code I wrote so far:
<?php
$guess = $_POST['guess'];
$number = rand(1,100);
$guessnumber = $_GET['guessnumber'];
echo "<H1> Guess #$guessnumber</H1>";
if($guess == $number){
echo '<BR>';
echo 'You win!!!';
echo "You took $guessnumber guesses.";
}else{
$guessnumber++;
echo "<A HREF=\"http://localhost/guessgame.php?guessnumber=$guessnumber\">Keep on guessing!</A>";
}
?>