'If' not working then...
Posted: Thu Oct 26, 2006 3:44 pm
I am just learning php and am creating a login page. After clicking submit, login.php handles the form data. login.php loads the account data from a text file and receives the data from the main form fine, but when I check to see if the entered data matches the data from text file, it should display the welcome message otherwise access denied. Even though the variables appear to be equal, it never passes the test. Here is the code I am writing.
text file:
Thanks for your help.
Code: Select all
<?php
$x="0";
$datasize = "5";
$success = "0";
$userbase="users.txt";
$fh=fopen($userbase,'r');
while($x<5){
$users[$x]=fgets($fh);
$pass[$x]=fgets($fh);
++$x;
}
fclose($fh);
$username=$_POST['Username'];
$password=$_POST['Password'];
echo "$username $password<br>";
$x = "0";
while( $x < $datasize && $success=="0" ){
echo "$users[$x] $pass[$x]<br>";
if($username==$users[$x]&&$password==$pass[$x])$success="1";
++$x;
}
if($success=="1")echo "Welcome $username<br>";
else echo "Access denied<br>";
?>Code: Select all
Adam
1928x
Chris
1235
mike
4912
harry
12000
lynn
00123