0

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 ....

Andrew Bro
  • 471
  • 2
  • 6
  • 20

1 Answers1

1

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);
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • @Hanky웃Panky That would fall under the heavy-handedness that `trim` has. Values in a "one-value per line" format should be allowed to have trailing spaces. In this case, we should *only* strip the end-of-line itself. – Niet the Dark Absol Feb 04 '16 at 05:52