我有一个php文件:
<?php
if (isset($_POST['submit'])) {
$file_name = 'hash.txt';
$user = md5($_POST['user']);
$password = md5($_POST['password']);
$handle = fopen('hash.txt',"r");
$read_file = file($file_name);
if ($user == $read_file[0] and $password == $read_file[1]) {
echo 'correct !';
} else {
echo 'incorrect !';
}
} else {
echo 'please input something';
}
?>
<body>
<form action="file_handle3.php" method="post">
User<input type="text" name="user"/><br/>
Password <input type="password" name="password"/>
<input type="submit" name="submit" value="submit"/>
</body>
和文件txt:hash.txt第一行是hello,第二行是world
5d41402abc4b2a76b9719d911017c592
7d793037a0760186574b0282f2f435e7
我想比较do值用户输入并将它们转换为md5然后与txt文件中的那个进行比较。我没有想法为什么我的代码输出正确的答案,即使我输入了正确的值(用户:你好)密码:世界)。抱歉我的英文不好
答案 0 :(得分:1)
当你使用file()时,文件中的每一行都会成为数组中的一个项目。
但是,该数组中的每个字符串都包含换行符(\ n)。所以你需要确保你做的事情......
trim($read_file[0],"\r\n");
...第一