PHP登录页面始终返回错误的用户名和密码
我有一个基本的登录页面,它接受用户输入的用户名和密码,并根据包含用户详细信息的XML文档检查输入的详细信息 问题是,即使用户名和密码正确,PHP文档仍然显示凭据不正确 谢谢PHP登录页面始终返回错误的用户名和密码,php,xml,login,Php,Xml,Login,我有一个基本的登录页面,它接受用户输入的用户名和密码,并根据包含用户详细信息的XML文档检查输入的详细信息 问题是,即使用户名和密码正确,PHP文档仍然显示凭据不正确 谢谢 <?php if(isset($_GET['login'])) { $id = ""; $errors = ""; $dom = DomDocument::load('../../data/customer.xml'); if(empty($
<?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>
例子
例子
example@email.com
1.
cb750e88
您使用的是$pwd
变量,而不是$password
:
if($inputEmail == $email->item($i)->textContent && $inputPassword == $pwd->item($i)->textContent) {
替换它:
if($inputEmail == $email->item($i)->textContent && $inputPassword == $password->item($i)->textContent) {
您使用的是
$pwd
变量,而不是$password
:
if($inputEmail == $email->item($i)->textContent && $inputPassword == $pwd->item($i)->textContent) {
替换它:
if($inputEmail == $email->item($i)->textContent && $inputPassword == $password->item($i)->textContent) {
请提供XML的示例。(更改敏感数据)检查$dom是否包含您希望它包含的内容(执行vardump)它不应该检查$u POST而不是$_GET@FirstOne添加了XML的摘录。是否确保正确加载了XML文档的内容?如果是,您是否可以尝试使用===而不是==来比较用户名和密码?我假设它们都是字符串,所以这应该强制进行文本比较。(更改敏感数据)检查$dom是否包含您希望它包含的内容(执行vardump)它不应该检查$u POST而不是$_GET@FirstOne添加了XML的摘录。是否确保正确加载了XML文档的内容?如果是,您是否可以尝试使用===而不是==来比较用户名和密码?我假设它们都是字符串,所以这应该强制进行文字比较。我不敢相信我漏掉了那个打字错误。谢谢你的帮助!我真不敢相信我漏掉了那个打字错误。谢谢你的帮助!