Valhalla Legends Forums Archive | Web Development | PHP Login Form w/o mySQL, Help appreciated

AuthorMessageTime
Black4C6F747573
Hey guys.  I'm working on a login script and I'm having some problems getting my code to compare two things correctly.  I have an html page with a form containing

<input type=text name=username>  :username<br>
<input type=text name=password> :password <br>

sending it to my php script

Then in my script i have this :
[code]

<html>
<body>
<?php


$teacher==$_POST["teacher"];
$password==$_POST["password"];

echo $teacher . "<br />";           
echo $password . "<br />";           

$success ==0;


if(!($t=fopen("teacher.txt","r")))
exit("Unable to open Teacher File");

while(!feof($t))
  {
$t_read = fgets($t,65535);
echo $t_read . "<br />";
if ($teacher == $t_read)
  {
$p_read = fgets($t,65535);
echo $p_read . "<br />";
if ($password == $p_read)
  {
echo "Successful Loggin!~";
$success == 1;
break;
  }
else
  {
echo "Password is invalid`-~";
  }
  }

else
  {
echo "That teacher could not be found in our database.";
fgets($t);
  }
  }
fclose($t);
?>
</body>
</html>
[/code]
I made the text file myself, because is_writeable would return false and chmod wouldnt work, so I couldn't write a script to register the usernames with fwrite. 

My database looks like this in notepad

tom
hhh
kelley
kkk
taylor
ttt

I want it to scan the database's 1st line and show me what it finds
[code]
$t_read = fgets($t,65535);
echo $t_read . "<br />";[/code]

then I want it to compare that to the name entered by the user
[code]
if ($teacher == $t_read)
  {
$p_read = fgets($t,65535);
echo $p_read . "<br />";
if ($password == $p_read)
  {
echo "Successful Loggin!~";
$success == 1;
break;
  }
else
  {
echo "Password is invalid`-~";
  }
  }

else
  {
echo "That teacher could not be found in our database.";
fgets($t);
  }[/code]

and in that script it does the same thing for the password.  I think that after it reads the teachers name from the database, it is set on the next line.  Then from there, if the teachers name matches the one entered, it reads the next line and compares that to the password.  Tom's password would be hhh.  Kelley's would be kkk... etc...  If the teachers nme doesnt match, it reads a new line with fgets, but doesnt do anything with it, inorder to set it at the next username line.

all of this works fine.  Visuallly, I see tom print out first, then hhh, for the things entered by the user in the form, then I see tom print out as the first line read out, so I know thats being compared to the tome entered, but I see a blank space after it when I highlight.  I'm thinking there might be some sort of charecter that was generated when I hand wrote my notepad document.  I could be wrong, but eitehr way its not working.  If you guys could give me a hand that would be thx :-).  I am trying to avoid usign mySQL as my webhost doesnt support it.

Sincerly,
Black Lotus 

P.S. dburg-php.bizhat.com is where I have hosted this.  The code above is in the file asdf.php, which is where the index page sends you.  Try using the username tom and the password hhh, or kelley kkk, taylor ttt.  Any help is appreciated.
November 24, 2004, 11:45 AM
Black4C6F747573
ty for help, the problem was i wasn't taking into account "\r\n" :-) im dumb.  TY anyways
November 24, 2004, 12:55 PM

Search