我正在尝试实现HTMLPURIFIER,但是在回显出我想要净化的HTML之后,我仍然得到
<img src="kay.JPG" alt="my picture" />作为所显示内容的一部分,同时也意味着要显示一张图片。我做错了什么?
function readmore_about_cs($row, $id)
{
$config = HTMLPurifier_Config::createDefault();
// configuration goes here:
$config->set('Core.Encoding', 'UTF-8');
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
$purifier = new HTMLPurifier($config);
if (isset($_GET['readmore'])) {
$nomore = ($row['about_church_of_christ_content']);
$pure_html = $purifier->purify($nomore);
echo htmlspecialchars($pure_html);
}
else
{
if (strlen(trim($row['about_church_of_christ_content'])) > 350)
{
$shortText = substr(trim($row['about_church_of_christ_content']), 0, 650);
$shortText .= '..<a href="http://127.0.0.1/church/about_cs.php?id='.$id.'&readmore=1">More</a>';
$pure_html = $purifier->purify($shortText);
echo htmlspecialchars($shortText) ;
}
}
} 发布于 2012-06-23 15:06:52
发生在你身上的是HTMLPurifier的默认行为,请注意,下面的解决方案将在你的安全上造成一个漏洞,因为你基本上是允许通过'src‘属性进行XSS攻击。
以下是您应该添加到代码中的内容:
// configuration goes here:
$config->set('HTML.Allowed','img[src], img[alt]');https://stackoverflow.com/questions/11092779
复制相似问题