用户不需要提交数字等。只要在他们的脑海中想一个。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>guess_game</title>
</head>
<body>
>if guess is too low, user presses 'low button' (same with high button)
<p>think of a number, 1-100.</p>
<form method="post">
<button type="submit" name="low">too low</button>
<button type="submit" name="high">too high</button>
<button type="submit" name="match">it's a match</button>
</form>
<?php
if (isset($_POST['low']))
{
>store $guess to be lowest number range of guess
$low = $guess;
}
else{$low=1;}
if (isset($_POST['high']))
{
$high = $guess;
}
else{$high=100;}
if (isset($_POST['match']))
{
print "thank you for playing";
}
?>
<form method="post">
<input type="hidden" name="hLow" id="hLow" value="<?php $low ?>">
>store $low,High vars to hidden field
<input type="hidden" name="hHigh" id="hHigh" value="<?php $high ?>">
</form>
<?php
>place values stored in hidden back to php var.
$hlow=$_POST['hLow'];
$hhigh=$_POST['hHigh'];
$guess=rand($hlow,$hhigh);
print "is the number $guess";
?>
</body>
</html>
到目前为止,此代码不会将任何值传递给隐藏字段。($guess 始终为 0)我希望 $guess 是 $low 和 $high 之间的随机数(存储在隐藏中)