This was posted ages ago but was lost when the forum went down, so I've decided to post it again.
This isn't the version which Mentor made changes to, as I have lost my copy of it.
You can play it at (It is another version, but is pretty similar):PHP Code:<?php
/*
-------------------------------
To customize the file name of the text
document and the character separating
the words, modify the code just bellow
this sentence.
------------------------------- */
$word_list_location = 'word_list.txt'; // Location of file containing the words
$word_separator = '|'; // Character used to separate the words
$file_name = 'hang_man.php'; // The name of this file
/* Don't edit bellow this line unless you know what you're doing */
session_start();
$users_guess = $_GET['guess'];
// If game hasn't started
if(!isset($_SESSION['hangman_word']))
{
unset($users_guess);
// Choose a random word
$handle = fopen($word_list_location, 'r');
$word_list = fread($handle, filesize($word_list_location));
$word_list = explode($word_separator, $word_list);
fclose($handle);
$word_list_count = (count($word_list) - 1);
$choosen_word = $word_list[rand(0, $word_list_count)];
// Put word into session
$_SESSION['hangman_word'] = $choosen_word;
}
// Check guess length
if(isset($users_guess) && strlen($users_guess) != 1)
{
session_destroy();
die("<script language=\"JavaScript\">
alert(\"Only enter one letter!\");
document.location.href=\"$file_name\";
</script>");
}
// Check if max loses has been met
if($_SESSION['hangman_loses'] > 9)
{
session_destroy();
die("<script language=\"JavaScript\">
alert(\"All lifes used up!\");
document.location.href=\"$file_name\";
</script>");
}
// Switches guessed letters to upper case
$correct_word = $_SESSION['hangman_word'];
$guess_check = str_replace($users_guess, strtoupper($users_guess), $correct_word);
// Checks if user guessed an incorrect letter
if (isset($users_guess) && $guess_check == $correct_word)
{
$_SESSION['hangman_loses']++;
}
else
{
$_SESSION['hangman_word'] = $guess_check;
// Check for win
if($_SESSION['hangman_word'] == strtoupper($_SESSION['hangman_word']))
{
session_destroy();
die("<script language=\"JavaScript\">
alert(\"You have won!\");
document.location.href=\"$file_name\";
</script>");
}
}
?>
<html>
<head>
<title>Hang-man</title>
</head>
<body>
<form>
<input type="text" name="guess" size="1" maxlength="1" value="" />
<input type="submit" value="Go" />
<br />
Word:
<?php
// Print word, with lower caps (non-guessed) hidden
print ereg_replace('[a-z]','_ ', $_SESSION['hangman_word']);
?>
<br />
Lifes:
<?php
// Put loses as zero if unset
if(!isset($_SESSION['hangman_loses'])) $_SESSION['hangman_loses'] = 0;
print $_SESSION['hangman_loses'].'/10';
?>
</form>
</body>
</html>
http://www.thybag.co.uk/test/hangyman.php







The word was morning 






