一个过虑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. 如何在SpringBoot当中上传多个图片或者上传单个图片 工具类

    如何在SpringBoot当中上传多个图片[上传多个图片 ] 附赠工具类 1.SpringBoot 上传图片工具类 public class SpringUploadUtil { /*** * 上传图 ...

  2. WNDR4300v2 固件编译

    WNDR4300v2 固件编译 1.从官网下载源码   从官网找到 https://kb.netgear.com/2649/NETGEAR-Open-Source-Code-for-Programme ...

  3. bzoj1393 旅游航道

    Description SGOI旅游局在SG-III星团开设了旅游业务,每天有数以万计的地球人来这里观光,包括联合国秘书长,各国总统和SGOI总局局长等.旅游线路四通八达,每天都有总躲得载客太空飞船在 ...

  4. Djangio笔记

    django图解 新创建一个项目后的目录层级

  5. python开发_linecache

    #从linecache的名称,我们可以知道该模块和cache(缓存)有关 #linecache现把文件读入到缓存中,在以后访问文件的时候,就不必要再从硬盘读取 #所以经常用于那些读取频率很高的文件还可 ...

  6. Codeforces Beta Round #10 A. Power Consumption Calculation 水题

    A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description To ...

  7. PAT甲级1057. Stack

    PAT甲级1057. Stack 题意: 堆栈是最基础的数据结构之一,它基于"先进先出"(LIFO)的原理.基本操作包括Push(将元素插入顶部位置)和Pop(删除顶部元素).现在 ...

  8. HDU 4585 Shaolin(水题,STL)

    Shaolin Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  9. Single transistor provides short-circuit protection

    In certain dc/dc-converter applications, on-chip, cycle-by-cycle current limit may be insufficient p ...

  10. Gulp插件使用技巧

    目录: 插件的安装卸载 插件使用的基本流程 拆分任务 监听 默认任务 一.插件的安装卸载 安装: npm install gulp-less --save-dev 卸载 npm uninstall g ...