hi, i know this is a big post but plz read it, I really need to know this.
Ok, the following script is from a website, (hotscripts)
but I need to add a script, but not sure how,
I have had ago but it won't work,
Here is the original script:
<? session_start();
/* SESSION VARIABLES USED
games -> tracks number of games played
tc -> total count - tracks total number of guesses
c -> count - tracks number of guesses for current game
num -> number picked between 1-100
*/
// set guess to integer type so bad data is
// not passed in through the form. if so $guess=0
settype($guess,"integer");
// check if games is already initialized
if (!session_is_registered("games"))
{
session_register("games");
session_register("tc");
session_register("num");
session_register("c");
$games = 0;
$tc = 0;
$num = 0;
$c =0;
}
// if sbtn is not defined, then it should
// be the first time here...
if (!$sbtn) $sbtn="Play Again";
switch ($sbtn)
{
case "Play Again": // starts new game
$num = getRandomNumber();
// zero out current guess count
$c = 0;
break;
case "Guess": // checks guess
$c++; $tc++;
if ($guess > $num)
$msg = "Guess #$c => <b>$guess</b> - too <b>HIGH</b>. Guess Again.";
else if ($guess < $num)
$msg = "Guess #$c => <b>$guess</b> - too <b>LOW</b>. Guess Again.";
else
{
$msg = "Guess #$c => <b>$guess</b> is <b>CORRECT!!</b>";
$games++;
$correct = true;
}
break;
case "Reset Totals": // resets totals and continues
$games = 0;
$tc = 0;
$num = 0;
$c = 0;
case "Get Totals": // displays totals
$msg = formatTotals($games,$tc);
$correct = true;
break;
default:
$msg = "INVALID";
break;
}
?>
<head>
<title>Guess a Number</title>
</head>
<body bgcolor="#FFFFFF">
<b>DO NOT PRESS ENTER, IT WILL RESET THE GAME</b><br>
This is only a test for this game, so don't expect it to work 100%<br>
If you guess the number correct(more like when u guess it) You win 10 points
<p><hr size=1 noshade></p>
<h3>Guess a number between 1 and 100.</h3>
<p><?=$msg?></p>
<form action="<?=$SCRIPT_NAME?>" METHOD="POST">
<?
if ($correct)
{
print "<br>\n";
print '<input type="submit" name="sbtn" value="Play Again"> ' . "\n";
print '<input type="submit" name="sbtn" value="Get Totals"> ' . "\n";
}
else
{
print 'Your Guess: <input type="text" name="guess" size="4" maxlength="3" value=""> <input type="submit" name="sbtn" value="Guess">' . "\n";
}
?>
</form>
<br>
</body>
<?
/----------------------------------------------------------
FUNCTIONS
-----------------------------------------------------------/
function getRandomNumber()
{
// seed rand number and guess
mt_srand ((double) microtime() * 1000000);
return mt_rand(1,100);
}
function formatTotals($g,$t)
{
// set to integer so "bad data" can't
// be displayed
settype($g,"integer");
settype($t,"integer");
if ($g != 0) $a = round( ($t/$g), 2);
else $a = 0;
$rstr = '<table cellpadding="4" cellspacing="0" border="1">';
$rstr .= "<tr><td>Total Games Played: </td><td>$g </td></tr> \n";
$rstr .= "<tr><td>Average Guesses per Game: </td><td>". $a ." </td></tr> \n";
$rstr .= "</table><br>";
return $rstr;
}
?>
I need to add the following though:
<?php
} else {
$userlist = file("users.inc.php");
$done = false;
$auth = false;
$found = false;
$i = 0;
while ((!$found) && ($i<count($userlist))) {
$i++;
list($n1,$p1,$a1,$e1,$g1,$s1,$m1,$a1,$a2) = explode(':',$userlist[$i]);
$found = ($n1==$user);
echo "<br>";
} if ($correct) {
$m1 += $10;
$userlist[$i] = implode(':',array($n1,$p1,$a1,$e1,$g1,$s1,$m1,$a1,$a2));
$fd = fopen("users.inc.php","w");
fputs($fd,"<?php die(\"Access restricted\"); ?>\n");
for ($i=1; $i<count($userlist); $i++) {
fputs($fd,chop($userlist[$i])."\n");
}
fclose($fd);
echo "10 has been added";
}
}
?>
Please help me out here,