一个过虑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. Vue组件深入了解(组件注册和Prop)

    一.组件名 自定义组件的名称强烈推荐遵循W3C规范中的方式:字母全小写且必须包含一个连字符. 二.全局注册和局部注册的区别 全局注册 Vue.component进行注册.全局注册的可以在任何创建的实例 ...

  2. [转]ViewPager 详解(三)---PagerTabStrip与PagerTitleStrip添加标题栏的异同

      目录(?)[-] 一PagerTitleStrip Class Overview XML布局文件 重写适配器的getPageTitle函数 变量 初始化 重写CharSequence getPag ...

  3. mysql localhost登录和tcp/ip登录 strace

    http://blog.itpub.net/15480802/viewspace-1755100/

  4. ffplay播放器移植VC的project:ffplay for MFC

    本文介绍一个自己做的FFPLAY移植到VC下的开源project:ffplayfor MFC.本project将ffmpeg项目中的ffplay播放器(ffplay.c)移植到了VC的环境下.而且使用 ...

  5. Appium+python自动化22-Appium Desktop

    Appium Desktop 原滋原味的官方文档 Appium Desktop是一款用于Mac.Windows和Linux的开源应用,它提供了Appium自动化服务器在一个漂亮灵活的UI中的强大功能. ...

  6. easyui datagrid如何获取到每行的文本框

    在return '<input type="text" name="txtCount" class="inputvalue"/> ...

  7. Openshift 3.11和LDAP的集成

    1. OpenLDAP的安装 只记录主要步骤,详细可参考 https://access.redhat.com/solutions/2484371 # yum install -y openldap o ...

  8. Pydoc 本地 HTML 形式查看

    Pydoc 本地 HTML 形式查看 我们在编写Python代码时,常常会去查询某些模块及函数的使用,会选择 dir() 及 help() 函数.或查看 CHM 格式的Python帮助文档.或查看Py ...

  9. Create XML Files Out Of SQL Server With SSIS And FOR XML Syntax

    So you want to spit out some XML from SQL Server into a file, how can you do that? There are a coupl ...

  10. 18 个最好的CSS框架用于提高开发效率

    根据维基百科,CSS框架是事先准备好的库,是为了让使用层叠样式表语言来美化网页更容易,更符合标准.在这篇文章中,我们已经收集了一些现成的框架,这将使你减少你的任务流程和代码.我们希望你会发现列表中的方 ...