I have this php code:
$flag = 0;
$f = fopen("1.txt", "r");
while (!feof($f))
{
$a = fgets($f);
$b = explode(",", $a);
if ($_POST['username'] == $b[0]&& $_POST['password'] == $b[1])
{
$flag = 1;
echo ("Correct");
break;
}
}
if ($flag == 0)
echo ("Incorrect");
fclose($f);
and 1.txt file is this:
1,1
2,2
3,3
4,4
5,5
I send data to my php page that have just this code but I always get Incorrect. I don’t know why if doesn’t work!(I checked the $_POST['username'] and $_POST['password'] but all were correct!) can anybody help me?
You may need to
trim($b[1])because it probably reads the new line into the string so$b[1]would never be equal.Edit:
Actually, you should just replace
$a = fgets($f);with$a = trim(fgets($f));