我有一个基本的登录页面,它接受用户输入的用户名和密码,并根据用户详细信息检查输入的详细信息。
问题是,即使用户名和密码正确,PHP文档仍然显示凭据不正确。
由于
<?php
if(isset($_GET['login'])) {
$id = "";
$errors = "";
$dom = DomDocument::load('../../data/customer.xml');
if(empty($_GET['email'])) {
$errors .= "Email field cannot be empty <br />";
}
else {
$inputEmail = $_GET['email'];
}
if(empty($_GET['password'])) {
$errors .= "Password field cannot be empty <br />";
}
else {
$inputPassword = $_GET['password'];
}
if(isset($inputEmail) && isset($inputPassword)) {
$email = $dom->getElementsByTagName('email');
$password = $dom->getElementsByTagName('password');
for($i = 0; $i < $email->length; $i++) {
if($inputEmail == $email->item($i)->textContent && $inputPassword == $pwd->item($i)->textContent) {
$id = $dom->getElementsByTagName("id")->item($i)->textContent;
break;
}
}
}
if($id == "") {
$errors .= "Incorrect username or password";
}
if($errors == "" ) {
echo true;
}
else {
echo $errors;
}
}
?>
根据要求,这里是XML的一个例子:
<customers>
<details>
<firstname>Example</firstname>
<lastname>Example</lastname>
<email>example@email.com</email>
<id>1</id>
<password>cb750e88</password>
</details>
</customers>
答案 0 :(得分:2)
您正在使用$pwd
变量而不是$password
:
if($inputEmail == $email->item($i)->textContent && $inputPassword == $pwd->item($i)->textContent) {
替换它:
if($inputEmail == $email->item($i)->textContent && $inputPassword == $password->item($i)->textContent) {