+ 1
Getting error in php string comparison [need help]
my code here and //Start login procedure... $userdir = "users//".$username."/auth.txt"; $passphrase= cryption($password,'e' ,$password); $details = file($userdir); //echo $details[0].'<br />'.$details[1].'<br />'; // GETTING ERROR IN THIS LINE // CANT COMPARE IDENTICAL VALUES TO TRUE if($user_c===$username && $pass_c===$passphrase){ //Start session & login; echo 'passwords match <br />'> initialise(); } else {echo 'passwords not matched <br />';} } PLZ HELP THE AUTH.TXT FILE CONSIST OF TWO LINES WITH ONE IS USERID AND OTHER IS PASSWORD
1 Odpowiedź
+ 2
Aman Kumar
I can't seem to find where $user_c, $username and $pass_c variable were declared, and I'm not sure what that cryption function does, I thought you were going to extract some values from $details array to compare with, can you tell me more what this code was about?
According to the PHP manual, the line break character are preserved in each array element, unless the FILE_IGNORE_NEW_LINES flag was passed, have you tried this yet? I was wondering if this was the issue.
Try to call the file() function passing that flag as the second argument, something like this:
$content = file(<file_path>, FILE_IGNORE_NEW_LINES);
And do a var_dump on the $content again to verify if there's a difference with the result from previous call to file() without passing the flag (note the string length).
http://php.net/manual/en/function.file.php
- See the "Return Value" section.
Hth, cmiiw