用php写的一个猜数字的程序

写一个php的猜数字的小程序,提高自己对php的熟悉程度。

 1 php
 2 $count=rand(0,100);
 3 $number = (isset($_POST['number'])) ? $_POST['number']:$count;
 4 
 5 if(!isset($_POST['guess'])){
 6  $message =  "please enter a number";
 7 }
 8 elseif(!is_numeric($_POST['guess'])){
 9  $message = "please make sure you entered a number";
10 }
11 elseif($_POST['guess'] > $number){
12  $message = "too big";
13 }
14 elseif($_POST['guess'] < $number){
15  $message = "too small";
16 }
17 else if($_POST['guess'] == $number){
18  header("Location:success.php");
19 }
20 else{
21  $message = "so confused";
22 }
23 ?>
24 
25 
26 
27 
28  A <span style="color:#0000ff;">number</span> guess game
29  
30  Document
31 
32 
33 

echo $number?>

34

echo $message?>

35
$_SERVER['PHP_SELF']; ?>" method="post"> 36

37 38 $number?>" > 39 40
41 42

总结:

1.第2行代码:$number = (isset($_POST['number'])) ? $_POST['number']:$count; 这样写可以保证每次刷新页面时答案不会变化;

2.第18行代码:header("Location:success.php");转去success.php页面;

3.第35行代码:  action = "";传回本页面;

4.第38行代码: 不在页面显示而传值;

5.(不在本项目中):输出PHP的安装信息

转载于:https://www.cnblogs.com/godlei/p/6501583.html

你可能感兴趣的:(用php写的一个猜数字的程序)