阻止除 <img> 之外的所有 html 标签
Prevent all html tags except <img>
为了防止对我的网站进行 XSS 攻击,我使用 PHP regex
喜欢
$regex = '/[<>]/';
$preg_replace= ($regex, '', $text);
使用此代码,我删除了 <
和 >
个字符,这样问题就解决了。但是现在我希望用户可以将 <img>
标签添加到我的网站,而 <script>
等其他标签必须仍然是 forbidden.How 我可以这样做吗?
你可以使用这个:
http://htmlpurifier.org/
如果这不是您要搜索的内容,您可以这样做:
http://php.net/manual/en/function.strip-tags.php
strip_stags($string, '<img>');
为了防止对我的网站进行 XSS 攻击,我使用 PHP regex
喜欢
$regex = '/[<>]/';
$preg_replace= ($regex, '', $text);
使用此代码,我删除了 <
和 >
个字符,这样问题就解决了。但是现在我希望用户可以将 <img>
标签添加到我的网站,而 <script>
等其他标签必须仍然是 forbidden.How 我可以这样做吗?
你可以使用这个:
http://htmlpurifier.org/
如果这不是您要搜索的内容,您可以这样做:
http://php.net/manual/en/function.strip-tags.php
strip_stags($string, '<img>');