0

当用户选择他时username,我会执行以下操作:

if($_POST['username'] != "") {
    $username = trim($_POST['username']);
    $username = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
}

但是如何使用 textarea,没有使用filter_var/的选项filter_input,那么我需要包括什么安全性?

strip_tags

htmlspecialchars

实体

你有什么建议吗?

问候!

4

1 回答 1

0

在你的情况下 - 因为你想从输入中删除任何标记......

$text = strip_tags($_POST['textarea']);

$text = $mysqli->real_escape_string($text);

mysqli->query("INSERT INTO yourtable (content) VALUES ('$text')");

...但是当您想再次将其输出到浏览器时-您仍然需要适当地对其进行转义....

if ($result = $mysqli->use_result()) {
    while ($row = $result->fetch_assoc()) {
        print "<div>" . nl2br(htmlentities($row['content'])) . "</div>";
    }
}
于 2014-04-07T13:08:57.037 回答