在我的代码中,我解析了一些html字符串和xml字符串,以便操纵他们的DOM。
在我解析它们之前,我通过在它们的开头搜索<?xml ... ?>
标记来区分字符串的类型,因此我知道是否应该使用parseAsHTML
解析它们或$.parseXML
功能。为了操纵他们的DOM树,我转发到下一个函数(操纵它们)他们的documentElement
属性(或者#34; body&#34;在html字符串的情况下,它给出相同的)。这就是问题所在。
对于HTMLDocument
个对象和XMLDocument
个对象,documentElement
似乎是HTMLElement
类型的实例。此外,documentElement
在其DOM树中没有<?xml ... ?>
标记,即使它来自xml字符串。这意味着如果我需要稍后检查我拥有哪种类型的DOM树,我就无法这样做,因为我的所有树都来自HTMLElement
类型。 html树也不是完整的树,所以我无法搜索标签或类似的东西。
我知道我可以自己传递Document
个对象,但它会让我改变已经获得Element
的数十个函数,所以我不想这样做。所以我的问题是如何区分元素?或者有没有办法制作某种XMLEntity
HTMLEntity
XMLDocument
属性<?php
$password = mysql_real_escape_string($_POST['password']);
$username = mysql_real_escape_string($_POST['username']);
//This string tells crypt to use blowfish for 5 rounds.
$Blowfish_Pre = '$2a$05$';
$Blowfish_End = '$';
// // PHP code you need to register a user
if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['register'])) {
global $valid;
user_reg_validate($con, $_POST['username'], $_POST['email'], $_POST['password'], $_POST ['password2']);
if ($valid != false) {
// Blowfish accepts these characters for salts.
$Allowed_Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
$Chars_Len = 63;
// 18 would be secure as well.
$Salt_Length = 21;
$mysql_date = date( 'Y-m-d' );
$salt = "";
for($i=0; $i<$Salt_Length; $i++) {
$salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
}
$bcrypt_salt = $Blowfish_Pre . $salt . $Blowfish_End;
$hashed_password = crypt($password, $bcrypt_salt);
$sql = "INSERT INTO login (username, salt, password) VALUES ('$username', '$salt', '$hashed_password')";
mysqli_query($con, $sql) or die( mysql_error() );
}
}
if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['login'])) {
global $valid;
user_login_validate($con, $_POST['username'], $_POST['password']);
if($valid != false) {
// Now to verify a user’s password
$sql = "SELECT salt, password FROM login WHERE username='$username'";
$result = mysqli_query($con, $sql) or die( mysql_error() );
$row = mysqli_fetch_assoc($result);
$hashed_pass = crypt($password, $Blowfish_Pre . $row['salt'] . $Blowfish_End);
echo $hashed_pass . "</br>";
echo $row['password'] . "</br>";
if ($hashed_pass == $row['password']) {
echo 'Password verified!';
} else {
echo 'There was a problem with your user name or password.';
}
}
}
?>
,以便我能够有所作为?
感谢您的帮助!
如果有什么不清楚,你可以自由提问,我会尝试更好地解释这种情况。