是否建议在 php 中使用一个结合两个或多个内置清理函数的清理函数?
是否可以使用一个函数来清理由于表单提交或任何其他请求而输入的输入。这节省了时间,但有效性和效率的问题仍然困扰着我。例如,
function clearSpecialChars($str)
{
$str=htmlentities($str);
$str=strip_tags($str);
$str=mysql_real_escape_string($str);
return $str;
}
当我收到表单提交时,我会这样做:
$username=clearSpecialChars($_REQUEST['username']);
$email=clearSpecialChars($_REQUEST['email']);
从根本上来说,我不希望用户输入任何 html 输入。
Is it okay to employ a function that sanitizes the incoming inputs due to a form submission or any other request. It is time saving but the question of effectivenss and efficiency still haunts me. For instance,
function clearSpecialChars($str)
{
$str=htmlentities($str);
$str=strip_tags($str);
$str=mysql_real_escape_string($str);
return $str;
}
so that when I get a form submission I do:
$username=clearSpecialChars($_REQUEST['username']);
$email=clearSpecialChars($_REQUEST['email']);
Fundamentally, I am not desiring any html inputs from the user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个函数都有其自己的用途,您不应使用任何不符合其预期用途的函数。
就是这样。
each function serves its own purpose, you shouldn't use any function not for their intended use.
that's about it.
是的,您可以创建一个简单的函数来在使用值之前对其进行清理。我使用这样的函数:
Which escape ' and " 并转换 html 实体中的所有适用字符。我的其他选项更复杂,但您可以从它开始。
Yes, you can create a simple function to sanitize a value before use it. I use a function like that:
Which escape ' and " and convert all applicable character in html entities. Mine is more complicated with other option, but you can begin from it.