Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 处理获取的数据时的额外清理_Php_Security_Prepared Statement_Sanitization - Fatal编程技术网

Php 处理获取的数据时的额外清理

Php 处理获取的数据时的额外清理,php,security,prepared-statement,sanitization,Php,Security,Prepared Statement,Sanitization,我从数据库中提取了一些数据(在进入数据库的过程中用一条准备好的语句对数据进行了清理)。当使用这些数据时,我认为我必须使用htmlspecialchars()函数,但使用了包含特殊字符的密码后,这破坏了代码,因为它明显地改变了您当前的代码是正确和安全的。你不需要其他任何东西 没有输入净化这样的东西准备好的语句不会清理数据。它们可以防止SQL注入,因为数据是与查询分开发送的 htmlspecialchars()可防止XSS攻击。将数据输出到HTML时使用它。不要在输入时使用它,因为它会损坏您的数据

我从数据库中提取了一些数据(在进入数据库的过程中用一条准备好的语句对数据进行了清理)。当使用这些数据时,我认为我必须使用htmlspecialchars()函数,但使用了包含特殊字符的密码后,这破坏了代码,因为它明显地改变了
您当前的代码是正确和安全的。你不需要其他任何东西

没有输入净化这样的东西准备好的语句不会清理数据。它们可以防止SQL注入,因为数据是与查询分开发送的

htmlspecialchars()
可防止XSS攻击。将数据输出到HTML时使用它。不要在输入时使用它,因为它会损坏您的数据


切勿以任何方式修改密码。直接在输入上使用
password\u hash()
,并将其保存到数据库中。

SQL和XSS注入是不同的问题。每个
htmlspecialchars
都需要不同的解决方案来阻止XSS注入。仅用于输出。你不应该输出密码,如果你这样做了,那应该是胡言乱语,因为它是散列的。嗨@user3783243这就是我的想法。我想请求确认,因为我是PHP新手。感谢您抽出时间发表评论。
if (isset($_POST['login'])) {

    $email = $_POST['email'];

    $stmt = $connection->prepare("SELECT * FROM users WHERE email = ? ");
    $stmt->bind_param("s", $email );

    $stmt->execute();

    $result = $stmt->get_result();

    // assign columns from the database to variables
    while ($row = mysqli_fetch_array($result)) {

       $db_id = $row['ID'];
       $db_firstname = $row['firstname'];
       $db_email = $row['email'];
       $db_password = $row['password'];

    }

    $stmt->close();
    $connection->close();

    // code will go here that checks if the email and password match and then create a $_SESSION

}