过滤在线编辑器产生的不安全html代码.
来源:互联网 发布:mac flash 制作软件 编辑:程序博客网 时间:2024/06/03 17:41
<?php
/**
* 过滤在线编辑器产生的不安全html代码.
*
* PHP versions 4 and 5
*
* @copyright 版权所无,任意传播.
* @link http://www.52sunny.net
* @name html过滤
* @version v 0.0.10
* @author Lucklrj (sunny_lrj@yeah.net,qq:7691272)
* @lastmodified 2006-06-09 10:42 (Tue, 2006-06-09)
* @notice 此版本只过滤js,框架,表单。
作者能力有限,使用本程序若产生任何安全问题,与本人无关。
欢迎来信与我交流。
*/
$str="<tr><td bgcolor='#FFFFFF'>
<div style='url(123.offsetWidth)>";
//$str="url(javascript:x)";
/*不需要过滤的数组*/
$htm_on=array(
"<acronym","acronym>",
"<baseFont","baseFont>",
"<button","button>",
"<caption","caption>",
"<clientInformation","clientInformation>",
"<font","font>",
"<implementation","implementation>",
"<button","button>",
"<location","location>",
"<option","option>",
"<selection","selection>",
"<strong","strong>");
$htm_on_uper=array(
"<ACRONYM","ACRONYM>",
"<BASEFONT","BASEFONT>",
"<BUTTON","BUTTON>",
"<CAPTION","CAPTION>",
"<CLIENTINFORMATION","CLIENTINFORMATION>",
"<FONT","FONT>",
"<IMPLEMENTATION","IMPLEMENTATION>",
"<BUTTON","BUTTON>",
"<LOCATION","LOCATION>",
"<OPTION","OPTION>",
"<SELECTION","SELECTION>",
"<STRONG","STRONG>");
/*字符格式*/
$str=strtolower($str);
$str=preg_replace("/s+/", " ", $str);//过滤回车
$str=preg_replace("/ +/", " ", $str);//过滤多个空格
/*过滤/替换几种形式的js*/
$str=preg_replace("/<(script.*?)>(.*?)<(/script.*?)>/si","",$str);//删除<script>。。。</script>格式,
//$str=preg_replace("/<(script.*?)>(.*?)<(/script.*?)>/si","</1>/2</3>",$str);//替换为可以显示的,
$str=preg_replace("/<(script.*?)>/si","",$str);//删除<script>未封闭
//$str=preg_replace("/<(script.*?)>/si","</1>",$str);//替换未封闭
/*删除/替换表单*/
$str=preg_replace("/<(/?form.*?)>/si","",$str);//删除表单
//$str=preg_replace("/<(/?form.*?)>/si","</1>",$str);//替换表单
$str=preg_replace("/<(i?frame.*?)>(.*?)<(/i?frame.*?)>/si","",$str);//删除框架
//$str=preg_replace("/<(i?frame.*?)>(.*?)<(/i?frame.*?)>/si","</1>/2</3>",$str);//替换框架
/*过滤on事件*/
$str=preg_replace("/href=(.+?)(["|'| |>])/ie","'href='.strtoupper('/1').'/2'",$str);//把href=涉及到的on转换为大写。
$str=str_replace($htm_on,$htm_on_uper,$str);//把<font,font>换为大写,dhtml标签字符,正则判断太烦琐,采用转换办法。
$str=preg_replace("/(on[^ .<>]+?)([ |>])/s","/2",$str);//取掉on事件
/*过滤超级连接的js*/
$str=preg_replace("/(href|src|background|url|dynsrc|expression|codebase)[=:(]([ "']*?w+..*?|javascript|vbscript:[^>]*?)()?)([ >/])/si","/1='#' /3/4",$str);//取掉href=javascript:
//返回小写字符
$str=strtolower($str);
$str=str_replace("&","&",$str);
echo $str;
?>
/**
* 过滤在线编辑器产生的不安全html代码.
*
* PHP versions 4 and 5
*
* @copyright 版权所无,任意传播.
* @link http://www.52sunny.net
* @name html过滤
* @version v 0.0.10
* @author Lucklrj (sunny_lrj@yeah.net,qq:7691272)
* @lastmodified 2006-06-09 10:42 (Tue, 2006-06-09)
* @notice 此版本只过滤js,框架,表单。
作者能力有限,使用本程序若产生任何安全问题,与本人无关。
欢迎来信与我交流。
*/
$str="<tr><td bgcolor='#FFFFFF'>
<div style='url(123.offsetWidth)>";
//$str="url(javascript:x)";
/*不需要过滤的数组*/
$htm_on=array(
"<acronym","acronym>",
"<baseFont","baseFont>",
"<button","button>",
"<caption","caption>",
"<clientInformation","clientInformation>",
"<font","font>",
"<implementation","implementation>",
"<button","button>",
"<location","location>",
"<option","option>",
"<selection","selection>",
"<strong","strong>");
$htm_on_uper=array(
"<ACRONYM","ACRONYM>",
"<BASEFONT","BASEFONT>",
"<BUTTON","BUTTON>",
"<CAPTION","CAPTION>",
"<CLIENTINFORMATION","CLIENTINFORMATION>",
"<FONT","FONT>",
"<IMPLEMENTATION","IMPLEMENTATION>",
"<BUTTON","BUTTON>",
"<LOCATION","LOCATION>",
"<OPTION","OPTION>",
"<SELECTION","SELECTION>",
"<STRONG","STRONG>");
/*字符格式*/
$str=strtolower($str);
$str=preg_replace("/s+/", " ", $str);//过滤回车
$str=preg_replace("/ +/", " ", $str);//过滤多个空格
/*过滤/替换几种形式的js*/
$str=preg_replace("/<(script.*?)>(.*?)<(/script.*?)>/si","",$str);//删除<script>。。。</script>格式,
//$str=preg_replace("/<(script.*?)>(.*?)<(/script.*?)>/si","</1>/2</3>",$str);//替换为可以显示的,
$str=preg_replace("/<(script.*?)>/si","",$str);//删除<script>未封闭
//$str=preg_replace("/<(script.*?)>/si","</1>",$str);//替换未封闭
/*删除/替换表单*/
$str=preg_replace("/<(/?form.*?)>/si","",$str);//删除表单
//$str=preg_replace("/<(/?form.*?)>/si","</1>",$str);//替换表单
$str=preg_replace("/<(i?frame.*?)>(.*?)<(/i?frame.*?)>/si","",$str);//删除框架
//$str=preg_replace("/<(i?frame.*?)>(.*?)<(/i?frame.*?)>/si","</1>/2</3>",$str);//替换框架
/*过滤on事件*/
$str=preg_replace("/href=(.+?)(["|'| |>])/ie","'href='.strtoupper('/1').'/2'",$str);//把href=涉及到的on转换为大写。
$str=str_replace($htm_on,$htm_on_uper,$str);//把<font,font>换为大写,dhtml标签字符,正则判断太烦琐,采用转换办法。
$str=preg_replace("/(on[^ .<>]+?)([ |>])/s","/2",$str);//取掉on事件
/*过滤超级连接的js*/
$str=preg_replace("/(href|src|background|url|dynsrc|expression|codebase)[=:(]([ "']*?w+..*?|javascript|vbscript:[^>]*?)()?)([ >/])/si","/1='#' /3/4",$str);//取掉href=javascript:
//返回小写字符
$str=strtolower($str);
$str=str_replace("&","&",$str);
echo $str;
?>
- 过滤在线编辑器产生的不安全html代码.
- 过滤html在线编辑器产生有危害代码
- 在线HTML编辑器代码
- 运行HTML代码的在线编辑器
- 在线Html编辑器粘贴过滤技术详解
- 过滤不安全代码!
- 编辑器。以及过滤成安全的HTML代码
- 在html中引入在线编辑器的代码
- 过滤不安全的字符串
- 解决FCKeditor在线文本编辑器自动过滤HTML标签的方法
- c#过滤在线编辑器的危险字符
- HTML在线编辑器的基本概念
- HTML在线编辑器的基本概念
- 让ckeditor 在线编辑器 不过滤html,head,title
- 让ckeditor 在线编辑器 不过滤html,head,title
- HTML在线编辑器的调用方法
- HTML在线编辑器的调用方法
- HTML在线编辑器的调用方法
- 大觉寺,鹫峰,农家院 游玩
- 为何我们的爱要经历如此的痛彻心扉(转)
- mysql命令行常用命令
- smarty中的register_modifie函数
- Directx8 学习笔记
- 过滤在线编辑器产生的不安全html代码.
- 河南省对外合作项目管理系统(20080406)
- 因为性骚扰公司漂亮前台mm,被丫投诉,在公司混不下去了!!!要我自动离职! 怎么办?
- sqlserver 2000中存入大于65535长度的内容报错的处理
- 单片机初学经验谈
- Spring学习笔记——概念理解
- JAVA作业和课后习题解答1
- 实训JAVA语言设计——程序查错
- 实训JAVA语言设计——从键盘输入一个年份,判断是否是闰年