gpt4 book ai didi

php - htmlspecialchars() 应该用于输入信息还是输出之前?

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:06:41 26 4
gpt4 key购买 nike

我获取 $_POST 信息并将其存储在数据库中,稍后查询并将此信息打印给用户。我应该在插入此信息之前使用 htmlspecialchars() 还是在查询它之后再输出它?

此外,我需要让用户能够使用引号和其他日常特殊字符。我知道我可以使用标志 ENT_NOQUOTES 但感觉如果我这样做会留下安全漏洞。

我的网站允许使用 Bbcode,我希望用户能够使用日常字符而不必看到“amp;lt; &”。

耐心等待我<---鼓励菜鸟!谢谢:D

最佳答案

Should I use htmlspecialchars() before inserting this info or after I query it before I output it?

在插入之前转义目标代码的数据。即在你输出它之前。

这意味着您将保留原始形式的数据用于其他目的(例如输出给用户进行编辑,包括在电子邮件中、生成 PDF、搜索等)

In addition I need the ability for users to have the ability to use quotes and other everyday special chars. I know I can use the flag ENT_NOQUOTES but it feels like if I do that it leaves security holes.

htmlspecialchars() 将输入数据中的引号转换为 HTML。所以您不需要做任何特别的事情。

My site allows Bbcode

然后你需要有一个合适的 BBCode 解析器。

关于php - htmlspecialchars() 应该用于输入信息还是输出之前?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7245440/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com