Created
March 9, 2016 06:25
-
-
Save fhefh2015/9edc71b8ceebf724ae02 to your computer and use it in GitHub Desktop.
防XSS 防SQL注入的代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 过滤参数 | |
* @param string $str 接受的参数 | |
* @return string | |
*/ | |
static public function filterWords($str) | |
{ | |
$farr = array( | |
"/<(\\/?)(script|i?frame|style|html|body|title|link|meta|object|\\?|\\%)([^>]*?)>/isU", | |
"/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU", | |
"/select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile|dump/is" | |
); | |
$str = preg_replace($farr,'',$str); | |
return $str; | |
} | |
/** | |
* 过滤接受的参数或者数组,如$_GET,$_POST | |
* @param array|string $arr 接受的参数或者数组 | |
* @return array|string | |
*/ | |
static public function filterArr($arr) | |
{ | |
if(is_array($arr)){ | |
foreach($arr as $k => $v){ | |
$arr[$k] = self::filterWords($v); | |
} | |
}else{ | |
$arr = self::filterWords($v); | |
} | |
return $arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment