Reputation: 491
The function reads two strings from file data.db (utf-8). The file contains strings: '123' and '123'. I checked it via ECHO and it displays the content correctly. Thus im sure the problem is not in the file.
When I try to match the values with the file the variable $access never change.
//got data from $_POST....
function au_check($login,$psw){
$f = file('data.db');
$l = $f[0];
$p = $f[1];
$access = 'fail';
if ($login==$l && $psw==$p){
$access='CHANGED';
}
return $access;
}
echo (au_check($_POST['login'],$_POST['pass'])); //returns FAIL :((((
BUT! If i change my values DIRECTLY in code IT WORKS...
//got data from $_POST....
function au_check($login,$psw){
$f = file('data.db');
$l = '123';
$p = '123';
$access = 'fail';
if ($login==$l && $psw==$p){
$access='CHANGED';
}
return $access;
}
echo (au_check($_POST['login'],$_POST['pass'])); //returns CHANGED.
?>
plz help! how to fix and what is wrong? that's so weird ....
Upvotes: 0
Views: 45
Reputation: 324630
file
returns the lines, complete with newline character.
Use something like this to trim them off (the trim
function is too heavy-handed):
$lines = file('data.db');
$f = array_map(function($line) {return rtrim($line,"\r\n");},$lines);
Upvotes: 1