/**
* 安全过滤函数
*
* @param $string
* @return string
*/
function safe_replace($string) {
$string = str_replace('%20','',$string);
$string = str_replace('%27','',$string);
$string = str_replace('%2527','',$string);
$string = str_replace('*','',$string);
$string = str_replace('"','"',$string);
$string = str_replace("'",'',$string);
$string = str_replace('"','',$string);
$string = str_replace(';','',$string);
$string = str_replace('<','<',$string);
$string = str_replace('>','>',$string);
$string = str_replace("{",'',$string);
$string = str_replace('}','',$string);
$string = str_replace('','',$string);
return $string;
}
?>
/**
* 返回经addslashes处理过的字符串或数组
* @param $string 需要处理的字符串或数组
* @return mixed
*/
function new_addslashes($string) {
if(!is_array($string)) return addslashes($string);
foreach($string as $key => $val) $string[$key] = new_addslashes($val);
return $string;
}
?>
//对请求的字符串进行安全处理
/*
$safestep
0 为不处理,
1 为禁止不安全HTML内容(javascript等),
2 完全禁止HTML内容,并替换部份不安全字符串(如:eval(、union、CONCAT(、--、等)
*/
function StringSafe($str, $safestep=-1){
$safestep = ($safestep > -1) ? $safestep : 1;
if($safestep == 1){
$str = preg_replace("#script:#i", "script:", $str);
$str = preg_replace("#<[/]{0,1}(link|meta|ifr|fra|scr)[^>]*>#isU", '', $str);
$str = preg_replace("#[ ]{1,}#", ' ', $str);
return $str;
}else if($safestep == 2){
$str = addslashes(htmlspecialchars(stripslashes($str)));
$str = preg_replace("#eval#i", 'eval', $str);
$str = preg_replace("#union#i", 'union', $str);
$str = preg_replace("#concat#i", 'concat', $str);
$str = preg_replace("#--#", '--', $str);
$str = preg_replace("#[ ]{1,}#", ' ', $str);
return $str;
}else{
return $str;
}
}
?>
/**
+------------------------------------------------- ----------
* Output safe html, used to filter dangerous codes
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param string $text The string to be processed
* @param mixed $tags list of allowed tags, such as table|td|th|td
+------------------------------------------------- ----------
* @return string
+------------------------------------------------- ----------
*/
static public function safeHtml($text, $tags = null)
{
$text = trim($text);
//Completely filter comments
$text = preg_replace('//','',$text);
//Completely filter dynamic code
$ Text = Preg_replace ('/& LT;? |?'. '& GT;/', '', $ Text);
//Completely filter js
$text = preg_replace('/
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
|