我正在尝试使用XML和PHP创建登录表单,但始终出现错误。我的HTML文件:XML PHP登录错误
<form action="login.php" method="post">
<input type="text" name="username" />
<br>
<br>
<input type="password" name="pass" />
<br>
<br>
<input type="submit" value="Login!" />
</form>
我的PHP文件:
<?php
$xml = simplexml_load_file('users.xml');
$usr = $_POST['username'];
$pass = $_POST['pass'];
if(empty($usr)) {
die('Please enter an username!');
} elseif(empty($pass)) {
die('Please enter a password!');
}
$l_usr = null;
$pass_e = md5($pass);
foreach($xml->user->username as $username) {
if($username == $usr) {
$l_usr = $username;
}
}
if(empty($l_usr)) {
die('User Not Found!');
}
if(!$xml->user->$l_usr->password == $pass_e) {
die('Wrong Password!!');
}
echo 'Hello, '.$l_usr;
是我的代码。它不工作。 users.xml文件是这样的:
<users>
<user>
<username>doruk.ayar</username>
<password>96b9c62c86f35c209c5b8c302ba34175</password>
</user>
<user>
<username>mina.alpturer</username>
<password>32250170a0dca92d53ec9624f336ca24</password>
</user>
<user>
<username>efe.gormus</username>
<password>32250170a0dca92d53ec9624f336ca24</password>
</user>
</users>
它不工作。当我编写正确的用户名和密码时,它会显示“未找到用户!”。有人能帮我吗?
注:通行证:
doruk.ayar: 123pass
efe.gormus: pass123
mina.alpturer: pass123
你不使用数据库的任何(特殊)的原因吗?它也比文本文件少得多,并且更安全。 –
你也不应该使用MD5,你不应该使用这个代码,而不是如果它已经上线或已经生效。你**会被黑客入侵。 –
不要忽视我的意见,再次... **你会被黑客攻击**然后你会回来向我们说:“我的网站被黑了,我该怎么办?!!”* –