我对 PHP 相当陌生,但我正在尝试做一个猜谜游戏。这个想法是你猜测 1-100 之间的数字,并且代码意味着有一个随机分配的代码来猜测直到被猜到,目前只是在分配数字。所以每次我尝试猜测时它都不会随机化。
<?php
session_start();
$_SESSION[var_answer] = rand (1, 100);
$var_number = $_REQUEST['number'];
if($var_number == $_SESSION[var_answer]){
echo " That is correct ;)";
}
else if($var_number <0 || $var_number>100){
echo " Sorry your guess has to be between 0 and 100";
}else if($var_number==" "||$var_number==""){
echo " Please take a guess first!";
}else if($var_number < $_SESSION[var_answer]){
echo " Smaller than mine";
}else if($var_number > $_SESSION[var_answer]){
echo " Larger than mine";
}
echo '<br/><a href="RNGG.php"> return</a>';
?>
到目前为止,这个数字是随机的,但正如我所说,不是每次会话都保存。