PHP技巧:過濾在線編輯器產(chǎn)生的不安全html代碼_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:淺析FCKeditor 的配置和使用方法FCKeditor 是一個(gè)十分強(qiáng)大的網(wǎng)頁文本編輯器,它支持多種腳本編程語言(包括 PHP)和支持多國語言。 FCKeditor 截至 2008年4月6日,其最新版本是 2.6RC,RC 就是 Release Candidate,修訂后的候選版本,很可能作為該版本的穩(wěn)定版在未來發(fā)布。目前的最新的穩(wěn)定版
<?php
/**
* 過濾在線編輯器產(chǎn)生的不安全html代碼.
*
* PHP versions 4 and 5
*
* @copyright 版權(quán)所無,任意傳播.
* @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,框架,表單。
作者能力有限,使用本程序若產(chǎn)生任何安全問題,與本人無關(guān)。
歡迎來信與我交流。
*/ str="<tr><td bgcolor='#FFFFFF'>
<div style='url(123.offsetWidth)>";
//str="url(javascript:x)";
/*不需要過濾的數(shù)組*/
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);//過濾多個(gè)空格
/*過濾/替換幾種形式的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轉(zhuǎn)換為大寫。
str=str_replace(htm_on,htm_on_uper,str);//把<font,font>換為大寫,dhtml標(biāo)簽字符,正則判斷太煩瑣,采用轉(zhuǎn)換辦法。
str=preg_replace("/(on[^ .<>]+?)([ |>])/s","\2",str);//取掉on事件
/*過濾超級(jí)連接的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;
?>
/**
* 過濾在線編輯器產(chǎn)生的不安全html代碼.
*
* PHP versions 4 and 5
*
* @copyright 版權(quán)所無,任意傳播.
* @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,框架,表單。
作者能力有限,使用本程序若產(chǎn)生任何安全問題,與本人無關(guān)。
歡迎來信與我交流。
*/ str="<tr><td bgcolor='#FFFFFF'>
<div style='url(123.offsetWidth)>";
//str="url(javascript:x)";
/*不需要過濾的數(shù)組*/
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);//過濾多個(gè)空格
/*過濾/替換幾種形式的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轉(zhuǎn)換為大寫。
str=str_replace(htm_on,htm_on_uper,str);//把<font,font>換為大寫,dhtml標(biāo)簽字符,正則判斷太煩瑣,采用轉(zhuǎn)換辦法。
str=preg_replace("/(on[^ .<>]+?)([ |>])/s","\2",str);//取掉on事件
/*過濾超級(jí)連接的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;
?>
分享:解析PHP中多張圖片上傳并校驗(yàn)的實(shí)現(xiàn)單張的圖片上傳是不復(fù)雜的,這里涉及到多張圖片上傳和對(duì)圖片格式的校驗(yàn),保證上傳的一定是圖片,防止上傳其他文件到服務(wù)器。 基本實(shí)現(xiàn)算法是使用數(shù)組的形式,把所有的圖片提交個(gè)一個(gè)數(shù)組,對(duì)數(shù)組的元素進(jìn)行一個(gè)個(gè)的處理。 ?php /***************************
相關(guān)PHP教程:
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- 理解動(dòng)態(tài)網(wǎng)頁技術(shù)PHP與數(shù)組的應(yīng)用
- 如何通過PHP實(shí)現(xiàn)DataGrid功能
- PHP多個(gè)接口同個(gè)方法
- PHP中圖片等比縮放的實(shí)例
- PHP計(jì)算未知長度的字符串哪個(gè)字符出現(xiàn)的次數(shù)最多
- php啟動(dòng)時(shí)候提示PHP startup的解決方法
- 使用php實(shí)現(xiàn)下載生成某鏈接快捷方式的解決方法
- Zend Framework 入門——頁面布局
- 使用PHP腳本修改Linux或Unix系統(tǒng)口令
- 用動(dòng)態(tài)網(wǎng)頁技術(shù)PHP打造個(gè)人網(wǎng)站全攻略
- 相關(guān)鏈接:
- 教程說明:
PHP教程-PHP技巧:過濾在線編輯器產(chǎn)生的不安全html代碼
。