guessinggame

guessinggame - echo "<p>Number of guesses:

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
<?php session_start(); if (!isset($_SESSION['guess'])) { $RandNum = rand(0, 100); $_SESSION['guess'] = $RandNum; $_SESSION['guesses'] = 0; } if (isset($_GET['guessField'])) { if (!is_numeric($_GET['guessField']) && $_GET['guessField'] < 1 && $_GET['guessField'] > 100) die("<p>You must enter a number between 1 and 100! Click your browser's Back button to return to the Guessing form.</p."); $Guess = $_GET['guessField']; $RandNum = $_SESSION['guess']; $Guesses = $_SESSION['guesses']; $_SESSION['guess'] = $RandNum; $_SESSION['guesses'] = ++$Guesses; if ($Guess > $RandNum) echo "<p>You guessed too high!</p>"; else if ($Guess < $RandNum) echo "<p>You guessed too low!</p>"; else if ($Guess == $RandNum) echo "<p>Congratulations! You guessed the hidden number.</p>";
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: echo "<p>Number of guesses: $Guesses.</p>"; } ?> ? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Guessing Game</title> <?php if (isset($_GET['name'])) { echo "<p>Welcome back $Visitor! Number of visits: $Visits."; } ?> </head> <body> <h3>Guessing Game</h3> <p>Enter a number between 1 and 100, then press the Guess button.</p> <form action="GuessingGame.php" method="get"> <p><input type="text" name="guessField" /> <input type="Submit" value=" Guess " /></p> </form> <p> <a href='<?php echo "StartOver.php?PHPSESSID=" . session_id() ?>'>Start Over</a> </p> </body> </html>...
View Full Document

This note was uploaded on 02/13/2011 for the course IS 370 taught by Professor Wills,c during the Spring '11 term at Herzing.

Ask a homework question - tutors are online