Forum Moderators: coopster

Message Too Old, No Replies

Php Login Page

         

malcolmcroucher

5:40 pm on May 5, 2008 (gmt 0)

10+ Year Member



Hi ,

I created a login via a username and password . I have a else statement for when the username and password dot match the database.

In this particular query I am matching the username and password and able to log in ect I an trying to open up a new page from which you can select something . Every time i select somthing I get thrown out .

here is the code below :

$sql="SELECT * FROM person WHERE Email='$username' and Password='$password'";
Echo "$sql";

$result=mysql_query($sql) or die(mysql_error());
Echo "$result";
$count=mysql_num_rows($result);
Echo "$count";

if ($count == 1)
{
Echo"success";
session_register("username");
session_register("password");
Include "hangman.php" ;

}

else
{
Echo "please enter another username";
Include "login.php" ;
Exit();


}

It takes the user to a hangman game . but when i try and select an hangman letter it throws me back to the orignal login screen (login.php)

below is the hangman code :

$len_alpha = strlen($alpha);

if(isset($_GET["n"])) $n=$_GET["n"];
if(isset($_GET["letters"])) $letters=$_GET["letters"];
if(!isset($letters)) $letters="";

if(isset($PHP_SELF)) $self=$PHP_SELF;
else $self=$_SERVER["PHP_SELF"];

$links="";

$max=6;# maximum number of wrong
# error_reporting(0);
$list = strtoupper($list);
$words = explode("\n",$list);
srand ((double)microtime()*1000000);
$all_letters=$letters.$additional_letters;
$wrong = 0;

echo "<P><B>Play PHP Hangman Game</B> &nbsp; - &nbsp; Category: <B>$Category</B><BR>\n";

if (!isset($n)) { $n = rand(1,count($words)) - 1; }
$word_line="";
$word = trim($words[$n]);
$done = 1;
for ($x=0; $x < strlen($word); $x++)
{
if (strstr($all_letters, $word[$x]))
{
if ($word[$x]==" ") $word_line.="&nbsp; "; else $word_line.=$word[$x];
}
else { $word_line.="_<font size=1>&nbsp;</font>"; $done = 0; }
}

if (!$done)
{

for ($c=0; $c<$len_alpha; $c++)
{
if (strstr($letters, $alpha[$c]))
{
if (strstr($words[$n], $alpha[$c])) {$links .= "\n<B>$alpha[$c]</B> "; }
else { $links .= "\n<FONT color=\"red\">$alpha[$c] </font>"; $wrong++; }
}
else
{ $links .= "\n<A HREF=\"$self?letters=$alpha[$c]$letters&n=$n\">$alpha[$c]</A> "; }
}
$nwrong=$wrong; if ($nwrong>6) $nwrong=6;
echo "\n<p><BR>\n<IMG SRC=\"hangman_$nwrong.gif\" ALIGN=\"MIDDLE\" BORDER=0 WIDTH=100 HEIGHT=100 ALT=\"Wrong:

$wrong out of $max\">\n";

if ($wrong >= $max)
{
$n++;
if ($n>(count($words)-1)) $n=0;
echo "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n";
echo "<p><BR><FONT color=\"red\"><BIG>SORRY, YOU ARE HANGED!</BIG></FONT><BR><BR>";
if (strstr($word, " ")) $term="phrase"; else $term="word";
echo "The $term was \"<B>$word</B>\"<BR><BR>\n";
echo "<A HREF=$self?n=$n>Play again.</A>\n\n";
}
else
{
echo " &nbsp; # Wrong Guesses Left: <B>".($max-$wrong)."</B><BR>\n";
echo "<H1><font size=5>\n$word_line</font></H1>\n";
echo "<P><BR>Choose a letter:<BR><BR>\n";
echo "$links\n";
}
}
else
{
$n++;# get next word
if ($n>(count($words)-1)) $n=0;
echo "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n";
echo "<P><BR><BR><B>Congratulations! &nbsp;You win!</B><BR><BR><BR>\n";
echo "<A HREF=$self?n=$n>Play again</A>\n\n";
}

echo<<<endHTML

</DIV></BODY></HTML>

endHTML;
?>

Maybe it has something to do with sessions ?
Maybe it has something to do with hangman loading the same page after every suggestion ?

d40sithui

6:54 pm on May 5, 2008 (gmt 0)

10+ Year Member



do you have session_start() anywhere on your scripts? you'd need this on every page that you want to use sessions.
according to php.net, the use of session_register() is deprecated.
consider switching to something like
<?
session_start();
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
?>