图片:
代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="d.php" method="post" style="width: 300px;margin: auto;margin-top: 100px;">
<h2 style="color: #db9"> 猜一猜</h2>
<fieldset>
<legend>填一个1~10的整数</legend>
<input type="text" name="name" >
<br>
<button>提交</button>
</form>
</fieldset>
</body>
</html>
<?php
$name=$_POST['name'];
session_start();
$r=rand(1,10);
if (isset($_SESSION['name'])){
}else{
$_SESSION['name']=$r;
}
if($name>$_SESSION['name']){
print "<script>";
print "alert('猜大了');";
print "history.back();";
print "</script>";
}else if($name==$_SESSION['name']){
print "<script>";
print "alert('猜对了');";
print "history.back();";
print "</script>";
$_SESSION['name']=null;
}else if($name<$_SESSION['name']){
print "<script>";
print "alert('猜小了');";
print "history.back();";
print "</script>";
}
?>
|