我有用户名和密码输入的html注册表。用户名和密码存储在.txt
文件中,如下所示:
username1,password1
username2,password2
我需要将输入的用户名和密码与存储的用户名和密码相匹配。这是我的代码,但有些东西不起作用,有人可以建议吗?
<form action = "./get_form.php" method = "post" name = "form" >
Username:
<input type= "text" name = "username" >
Password:
<input type= "text" name = "passwords" >
Remember me:
<input type= "checkbox" name = "remember" value = "checked" >
<input type = "submit" name = "submit" value= "Submit Query" >
</form>
<?php
$username= $_POST["username"];
$password= $_POST["password"];
$contents = file("passwords.txt");
$found = false;
foreach ($contents as $line) {
$data = explode(',', $line);
if (($username === $data[0]) && ($password === $data[1])) {
$found = true;
}
}
?>