我想用php制作一个简单的游戏(猜测数字),我有3次尝试猜测数字..每次尝试后页面将如何刷新?刷新后保存尝试?
<html>
<head>
<title>Guessing Number</title>
<link rel="stylesheet" href=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
body{
background-color: #ecb731;
}
</style>
</head>
<body>
<center>
<div class="container">
<form method="post" action="">
<h1>Guessing Game</h1><br><br>
<label>Enter the number <input type="text" name="num">
</label><br><br>
<input type="submit" name="submit" class="btn btn-
primary" value="Check Number!">
</form>
</div>
</center>
</body>
</html>
<?php
$attempt = 0 ;
$number = 5;
if ( isset( $_POST['submit'] )){
$num = $_POST['num'];
}
while ($attempt < 3){
if ($num > $number){
echo "The number is bigger than the actual number";
exit;
}
if ($num < $number){
echo "The number is smaller than the actual number";
exit;
}
if ($num == $number){
header ("location:sucess.php");
}
else if ($attempt > 3) {
echo " you finished all allowed attempts";
break;
}
else
$attempt++;
}
?>
页面中的:sucess.php这段代码: 非常好,你成功!