一个过虑xxs的代码

public static function removeXSS($str) {
$str = str_replace('<!-- -->', '', $str);
$str = preg_replace('~/\*[ ]+\*/~i', '', $str);
$str = preg_replace('/\\\0{0,4}4[0-9a-f]/is', '', $str);
$str = preg_replace('/\\\0{0,4}5[0-9a]/is', '', $str);
$str = preg_replace('/\\\0{0,4}6[0-9a-f]/is', '', $str);
$str = preg_replace('/\\\0{0,4}7[0-9a]/is', '', $str);
$str = preg_replace('/&#x0{0,8}[0-9a-f]{2};/is', '', $str);
$str = preg_replace('/&#0{0,8}[0-9]{2,3};/is', '', $str);
$str = preg_replace('/&#0{0,8}[0-9]{2,3};/is', '', $str); $str = htmlspecialchars($str);
//$str = preg_replace('/</i', '<', $str);
//$str = preg_replace('/>/i', '>', $str); // 非成对标签
$lone_tags = array("img", "param", "br", "hr");
foreach ($lone_tags as $key => $val)
{
$val = preg_quote($val);
$str = preg_replace('/<' . $val . '(.*)(\/?)>/isU', '<' . $val . "\\1\\2>", $str);
$str = self::transCase($str);
$str = preg_replace_callback('/<' . $val . '(.+?)>/i', create_function('$temp', 'return str_replace(""","\"",$temp[0]);'), $str);
}
$str = preg_replace('/&/i', '&', $str); // 成对标签
$double_tags = array("table", "tr", "td", "font", "a", "object", "embed", "p", "strong", "em", "u", "ol", "ul", "li", "div", "tbody", "span", "blockquote", "pre", "b", "font");
foreach ($double_tags as $key => $val)
{
$val = preg_quote($val);
$str = preg_replace('/<' . $val . '(.*)>/isU', '<' . $val . "\\1>", $str);
$str = self::transCase($str);
$str = preg_replace_callback('/<' . $val . '(.+?)>/i', create_function('$temp', 'return str_replace(""","\"",$temp[0]);'), $str);
$str = preg_replace('/<\/' . $val . '>/is', '</' . $val . ">", $str);
}
// 清理js
$tags = Array(
'javascript',
'vbscript',
'expression',
'applet',
'meta',
'xml',
'behaviour',
'blink',
'link',
'style',
'script',
'embed',
'object',
'iframe',
'frame',
'frameset',
'ilayer',
'layer',
'bgsound',
'title',
'base',
'font'
); foreach ($tags as $tag)
{
$tag = preg_quote($tag);
$str = preg_replace('/' . $tag . '\(.*\)/isU', '\\1', $str);
$str = preg_replace('/' . $tag . '\s*:/isU', $tag . '\:', $str);
} $str = preg_replace('/[\s]+on[\w]+[\s]*=/is', '', $str); Return $str;
}

链接地址:https://github.com/sillydong/CZD_Yaf_Extension/blob/master/library/Tools.php

不错的yaf封闭mysql地址  https://github.com/jonsonxu/yaf

php 一个过虑xxs的代码的更多相关文章

  1. 给 VS 2010 选一个好用的代码行数统计器(转)

    给 VS 2010 选一个好用的代码行数统计器 分类: Tricks2011-02-25 05:40 3891人阅读 评论(0) 收藏 举报 2010c 推荐一个VS插件,支持2005/2008/20 ...

  2. 一个 11 行 Python 代码实现的神经网络

    一个 11 行 Python 代码实现的神经网络 2015/12/02 · 实践项目 · 15 评论· 神经网络 分享到:18 本文由 伯乐在线 - 耶鲁怕冷 翻译,Namco 校稿.未经许可,禁止转 ...

  3. 做了一个简易的git 代码自动部署脚本

    做了一个简易的git 代码自动部署脚本 http://my.oschina.net/caomenglong/blog/472665 发表于2个月前(2015-06-30 21:08)   阅读(200 ...

  4. 想做一个整合开源安全代码扫描工具的代码安全分析平台 - Android方向调研

    想做一个整合开源安全代码扫描工具的代码安全分析平台 - Android方向调研 http://blog.csdn.net/testing_is_believing/article/details/22 ...

  5. 一个只有99行代码的JS流程框架(二)

    欢迎大家关注腾讯云技术社区-博客园官方主页,我们将持续在博客园为大家推荐技术精品文章哦~ 张镇圳,腾讯Web前端高级工程师,对内部系统前端建设有多年经验,喜欢钻研捣鼓各种前端组件和框架. 导语 前面写 ...

  6. html是什么?一个完整的html代码告诉你(完整实例版)

    html什么意思?这篇文章主要为大家仔细的解释了HTML文档的一个基础的完整代码,还有具体的实例解释,让大家能一下就看懂HTML的基础结构和用法.下面我们一起来看看吧一.html是什么?点击查看htm ...

  7. 点击文字弹出一个DIV层窗口代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  8. (转)如何基于FFMPEG和SDL写一个少于1000行代码的视频播放器

    原文地址:http://www.dranger.com/ffmpeg/ FFMPEG是一个很好的库,可以用来创建视频应用或者生成特定的工具.FFMPEG几乎为你把所有的繁重工作都做了,比如解码.编码. ...

  9. 推荐一个小而美的Python代码格式化工具

    代码可读性是评判代码质量的标准之一,有一个衡量代码质量的标准是 Martin 提出的 “WFT” 定律,即每分钟爆出 “WTF” 的次数.你在读别人代码或者做 Code Review 的时候有没有 “ ...

随机推荐

  1. iptables数据包、连接标记模块MARK/CONNMARK的使用(打标签)

    MARK标记用于将特定的数据包打上标签,供iptables配合TC做QOS流量限制或应用策略路由. 看看和MARK相关的有哪些模块: ls /usr/lib/iptables/|grep -i mar ...

  2. ios:设置视图背景图片的方法

    1. 使用一个UIImageView实例做子视图,并且放最后面UIImageView *customBackgournd = [UIImageView alloc] initWithImage:[UI ...

  3. Surface Mount Package Details

    http://www.centralsemi.com/product/packages/index2.php http://www.infineon.com/cms/cn/product/packag ...

  4. wpf 分别用前台和后台 两种方法 绘制矩形 填充

    xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft ...

  5. node.js&pm2搭建node生产环境

    node.js下载地址https://nodejs.org/en/download/stable/ 下载截图 建议采用稳定编译过的版本,source code稍麻烦,编译过的直接可用,安装超级简单,红 ...

  6. jenkins报:反向代理设置有误

    1.如图所示: 2.点击更多信息,查看解决办法: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+says+my+reverse+proxy+s ...

  7. Spring3之InternalResourceViewResolver

    打开Spring的源代码,我们可以在org.springframework.web.servlet.view包下看到很多的 View和ViewResolver类;View类为我们提供一些缺省的待扩展的 ...

  8. 使用HttpClient发送请求接收响应

    1.一般需要如下几步:(1) 创建HttpClient对象.(2)创建请求方法的实例,并指定请求URL.如果需要发送GET请求,创建HttpGet对象:如果需要发送POST请求,创建HttpPost对 ...

  9. Orchard运用 - 定制呈现最新博客文章

    每个博客系统为了吸引更多访问量,一般都会在首页或侧边栏列举一些最新文章/随笔以获取更多点击.其实也就是查询出最新的几篇文章并按照简练的方式呈现,比如一般都只有标题及其对应的链接,有时也会标注一下作者和 ...

  10. Converting a fisheye image into a panoramic, spherical or perspective projection [转]

    Converting a fisheye image into a panoramic, spherical or perspective projection Written by Paul Bou ...