防止SQL注入的PHP 函数
2018-07-20 来源:open-open
SQL 注入或者 SQLi 常见的攻击网站的手段,使用下面的代码可以帮助你防止SQL注入
function clean($input)
{
if (is_array($input))
{
foreach ($input as $key => $val)
{
$output[$key] = clean($val);
// $output[$key] = $this->clean($val);
}
}
else
{
$output = (string) $input;
// if magic quotes is on then use strip slashes
if (get_magic_quotes_gpc())
{
$output = stripslashes($output);
}
// $output = strip_tags($output);
$output = htmlentities($output, ENT_QUOTES, 'UTF-8');
}
// return the clean text
return $output;
}
用法:
<?php $text = "<script>alert(1)</script>"; $text = clean($text); echo $text; ?>
标签: 代码
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:PHP解压ZIP文件
下一篇:PHP缩放图片
最新资讯
热门推荐