简单的 php 防注入、防跨站 函数
生活随笔
收集整理的這篇文章主要介紹了
简单的 php 防注入、防跨站 函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** 簡單的 php 防注入、防跨站 函數* @return String*/function fn_safe($str_string) {//直接剔除$_arr_dangerChars = array("|", ";", "$", "@", "+", "\t", "\r", "\n", ",", "(", ")", PHP_EOL //特殊字符
);//正則剔除$_arr_dangerRegs = array(/* -------- 跨站 --------*///html 標簽"/<(script|frame|iframe|bgsound|link|object|applet|embed|blink|style|layer|ilayer|base|meta)\s+\S*>/i",//html 屬性"/on(afterprint|beforeprint|beforeunload|error|haschange|load|message|offline|online|pagehide|pageshow|popstate|redo|resize|storage|undo|unload|blur|change|contextmenu|focus|formchange|forminput|input|invalid|reset|select|submit|keydown|keypress|keyup|click|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|mousedown|mousemove|mouseout|mouseover|mouseup|mousewheel|scroll|abort|canplay|canplaythrough|durationchange|emptied|ended|error|loadeddata|loadedmetadata|loadstart|pause|play|playing|progress|ratechange|readystatechange|seeked|seeking|stalled|suspend|timeupdate|volumechange|waiting)\s*=\s*(\"|')?\S*(\"|')?/i",//html 屬性包含腳本"/\w+\s*=\s*(\"|')?(java|vb)script:\S*(\"|')?/i",//js 對象"/(document|location)\s*\.\s*\S*/i",//js 函數"/(eval|alert|prompt|msgbox)\s*\(.*\)/i",//css"/expression\s*:\s*\S*/i",/* -------- sql 注入 --------*///顯示 數據庫 | 表 | 索引 | 字段"/show\s+(databases|tables|index|columns)/i",//創建 數據庫 | 表 | 索引 | 視圖 | 存儲過程 | 存儲過程"/create\s+(database|table|(unique\s+)?index|view|procedure|proc)/i",//更新 數據庫 | 表"/alter\s+(database|table)/i",//丟棄 數據庫 | 表 | 索引 | 視圖 | 字段"/drop\s+(database|table|index|view|column)/i",//備份 數據庫 | 日志"/backup\s+(database|log)/i",//初始化 表"/truncate\s+table/i",//替換 視圖"/replace\s+view/i",//創建 | 更改 字段"/(add|change)\s+column/i",//選擇 | 更新 | 刪除 記錄"/(select|update|delete)\s+\S*\s+from/i",//插入 記錄 | 選擇到文件"/insert\s+into/i",//sql 函數"/load_file\s*\(.*\)/i",//sql 其他"/(outfile|infile)\s+(\"|')?\S*(\"|')/i",);$_str_return = $str_string;//$_str_return = urlencode($_str_return);foreach ($_arr_dangerChars as $_key=>$_value) {$_str_return = str_ireplace($_value, "", $_str_return);}foreach ($_arr_dangerRegs as $_key=>$_value) { $_str_return = preg_replace($_value, "", $_str_return);}$_str_return = htmlentities($_str_return, ENT_QUOTES, "UTF-8", true);return $_str_return;
}
?
轉載于:https://www.cnblogs.com/daxian2012/p/10217922.html
總結
以上是生活随笔為你收集整理的简单的 php 防注入、防跨站 函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 并发编程之多线程
- 下一篇: 在centos安装redis