<?php $num_to_guess = 42; $message = ""; $num_tries = ( isset( $num_tries ) ) ? ++$num_tries : 0;
if ( ! isset( $guess ) ){ $message = "Welcome to the guessing machine!"; }elseif( $guess > $num_to_guess ){ $message = "$guess is too big!"; }elseif( $guess < $num_to_guess ){ $message = "$guess is too small!"; }else{ $message = "Well done!"; }
$guess = (int) $guess; ?> <html> <head> <title>Saving state with a hidden field</title> </head> <body> <h1> <?php print $message ?> </h1> Guess number: <?php print $num_tries?> <form action="<?php print $PHP_SELF?>" method="POST"> Type your guess here: <input type="text" name="guess" value="<?php print $guess?>"> <input type="hidden" name="num_tries" value="<?php print $num_tries?>"> </form> </body> </html>
|