<?php 

session_start
();
session_register("count");
session_register("number");

function 
showForm() {
   print(
"<hr><form action='guessinggame.php' method='post'>");
   print(
"<p>Enter your guess: <input type=text name=guess size=7> ");
   print(
"<input type=submit></p>");
   print(
"</form><hr>");
}

print(
"<html>");
print(
"<head>");
print(
"<title>Guessing Game</title>");
print(
"</head>");
print(
"<body bgcolor=white>");

print(
"<h1>Guessing Game</h1>");

if (
$count == 0) {
   
srand ((double) microtime() * 1000000);
   
$number rand(1,100);
   
$count 1;
   print(
"<p>Welcome to the Great Web-Based Computer Guessing Game</p>");
   print(
"<p>The computer will pick a random number in the range 1 to 100</p>");
   print(
"<p>Try to guess what it is!</p>");
   
showForm();
}
else {
   
$guess = (int)$guess;
   if (
$guess == 0) {
      print(
"<p>Try to guess the computer's number, between 1 and 100!</p>");
      
showForm();
   }
   else if (
$guess == $number) {
      print(
"<p><b>Congratulations.  You guessed the number.</b></p>");
      print(
"<p>You used $count guesses.</p>");
      print(
"<p>If you want to play again, ");
      print(
"<a href='guessinggame.php'>click here</a>.</p>");
      
$count=0;
   }  
   else if (
$guess $number) {
      print(
"<p>Sorry, $guess is too high.  Try again.</p>");
      
$count $count 1;
      
showForm();
   }
   else {
      print(
"<p>Sorry, $guess is too low.  Try again.</p>");
      
$count $count 1;
      
showForm();
   }
}

print(
"</body>");
print(
"</html>");

?>