Просмотр файла index.php

Размер файла: 6.49Kb
<?php 

####################################
##                                ##
##      Made by Bananiel          ##
##                                ##
## Comments 2 [email protected] ##
## 4more scripts take a look @    ##
##   http://www.bananiel.nl       ##
##                                ##
####################################

#############
## CONFIG  ##
## SECTION ##
#############

$lownumber = 0;         // Lowest number must be lower then higest number
$highnumber = 100;        // Higest number must be higher than lowest number
$maxhighscore = 100;    // How mutch entries in the highscore ? 0 for endless
$date = date("d-m-Y");  // Here you can change the time stamp.

#############
## END OF  ##
## CONFIG  ##
## SECTION ##
#############

session_start(); 
session_name($REMOTE_ADDR);

if( isset($usernick) )
{

	$usernick = trim($usernick);
	if( $usernick == "" )
	{
                                                                                 ###### NONAME PAGE ######


echo "<html>\r
<head>\r
<title>HiLower Game</title>\r
</head>\r
<body bgcolor=\"black\" onload=\"document.forms[0].usernick.focus()\">\r

	<table class=\"sitemenu\" align=\"center\" bgcolor=\"gray\" bordercolor=\"silver\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\">\r
	<tr align=\"center\">\r
	<td class=\"sitemenutopic\"><b>.: No Name :.</b></td></tr>\r
	<tr><td>\r

		<table class=\"site\" align=\"center\" bordercolor=\"silver\" border=\"0\" cellpadding=\"0\">\r
		<tr><td align=\"center\">\r

		<form action=\"$PHP_SELF\" method=\"post\">\r
		<b>Smarty you have to enter a name.</b><br>\r
		Enter your name:<br>
		<input type=\"text\" name=\"usernick\" maxlength=\"25\"><br>\r
		<input type=\"submit\" value=\"Submit\">\r
		</form>\r

		</td></tr>\r
		</table>\r

	</td></tr>\r
	</table>\r
</body>\r
</html>
";
	exit;	
	}
}
                                                                                 ###### DB WRITE ######
if( $_SESSION['do'] == "write" )
{
	$usernick = htmlspecialchars($usernick);
	$usernick = stripslashes($usernick);
	$usernick = substr($usernick, 0, 25);
	$file = fopen("list.txt","a+");
	fwrite($file,"\n$num_tries|$usernick|$date|");
	fclose($file);

	$file = "list.txt";
	$fd = fopen ($file, "r");
	$contents = fread ($fd, filesize ($file));
	fclose ($fd);
	$pieces = explode ("\n", $contents);
	natcasesort($pieces);
	if( $maxhighscore != "0" )
	{$pieces = array_slice($pieces, 0, $maxhighscore);}

	$fp = fopen ("list.txt", "w+");
	$blarg = implode("\n",$pieces); 
	fwrite($fp,$blarg,strlen($blarg));
	fclose ($fp);

                                                                                 ###### SCORE ADDED PAGE ######
echo "<html>\r
<head>\r
<title>HiLower Game</title>\r
</head>\r
<body bgcolor=\"black\">\r

	<table class=\"sitemenu\" align=\"center\" bgcolor=\"gray\" bordercolor=\"silver\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\">\r
	<tr align=\"center\">\r
	<td class=\"sitemenutopic\"><b>.: Score Added :.</b></td></tr>\r
	<tr><td>\r

		<table class=\"site\" align=\"center\" bordercolor=\"silver\" border=\"0\" cellpadding=\"0\">\r
		<tr><td align=\"center\">\r
		You score has been recorded $usernick.<br>\r
		</td></tr>\r
		</table>\r

	</td></tr>\r
	<tr><td>Click <a href=\"$PHP_SELF\">here</a> to play another game.<br>\r
		and   <a href=\"highscore.php\">here</a> for the highscore.\r
	</td></tr>\r
	</table>\r
</body>\r
</html>
";
    Session_destroy();
	exit;
}

if( $lownumber >= $highnumber )
{
print "Config error edit \$lownumber & \$highnumber";
exit;
}

$num_to_guess = ( isset( $num_to_guess ) ) ? $num_to_guess : rand($lownumber,$highnumber);
session_register("num_to_guess");

$message = "";
$num_tries = ( isset( $num_tries ) ) ? ++$num_tries : 0;
session_register("num_tries");
if ( ! isset( $guess ) )
   {
   $message = "<br>Welcome to the HiLower Game";
   }
elseif ( $guess < $lownumber | $guess > $highnumber )
   {
   $message = "<b><br>$guess is not between $lownumber and $highnumber</b>";
   --$num_tries;
   }
elseif ( $guess > $num_to_guess )
   {
   $message = "<b>$guess is too big!</b><br>Try a smaller number";
   }
elseif ( $guess < $num_to_guess )
   {
   $message = "<b>$guess is too small!</b><br>Try a larger number";
   }
elseif ( $guess == $num_to_guess )
   {
                                                                                 ###### WON PAGE ######
echo "<html>\r
<head>\r
<title>HiLower Game</title>\r
</head>\r
<body bgcolor=\"black\" onload=\"document.forms[0].usernick.focus()\">\r

	<table class=\"sitemenu\" align=\"center\" bgcolor=\"gray\" bordercolor=\"silver\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\">\r
	<tr align=\"center\">\r
	<td class=\"sitemenutopic\"><b>.: YOU WON :.</b></td></tr>\r
	<tr><td>\r

		<table class=\"site\" align=\"center\" bordercolor=\"silver\" border=\"0\" cellpadding=\"0\">\r
		<tr><td align=\"center\">\r

		<form action=\"$PHP_SELF\" method=\"post\">\r
		Your a Winner with $num_tries tries.<br>\r
		Enter your name:<br>
		<input type=\"text\" name=\"usernick\" maxlength=\"25\"><br>\r
		<input type=\"submit\" value=\"Submit\">\r
		</form>\r

		</td></tr>\r
		</table>\r

	</td></tr>\r
	</table>\r
</body>\r
</html>
";


	$do = "write";
	session_register("do");
	exit;
   }
else
   {
   $message = "<font color=\"red\">Error</font><br>\n";
   }
                                                                                 ###### GUESS PAGE ######
?>
<html>
<head>
<title>HiLower Game</title>
</head>
<body bgcolor="black" onload="document.forms[0].guess.focus()">

	<table class="sitemenu" align="center" bgcolor="gray" bordercolor="silver" border="1" cellpadding="5" cellspacing="0">
	<tr align="center">
	<td class="sitemenutopic"><b>.: HiLower Game :.</b></td></tr>
	<tr><td>

		<table class="site" align="center" bordercolor="silver" border="0" cellpadding="0">
		<tr><td align="center">

		<b>Guess a number between <?php print "$lownumber and $highnumber" ?></b><br>
		Tries: <?php print $num_tries ?><br>
		<?php print $message ?><br>
		<form action="<?php print $PHP_SELF ?>" method="POST">
		Type your guess here:<br>
		<input type="text" name="guess"><br>
		<input type="submit" value="Submit">
		</form>

		</td></tr>
		</table>

	</td></tr>
	<tr><td>Click <a href="<?php print $PHP_SELF ?>">here</a> to play another game.<br>
		and   <a href="highscore.php">here</a> for the highscore.
	</td></tr>
	</table>
</body>
</html>