最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php 安全過濾函數(shù)代碼

 更新時間:2011年05月07日 20:10:05   投稿:mdxy-dxy  
php 安全過濾函數(shù)代碼,防止用戶惡意輸入內(nèi)容。

復(fù)制代碼 代碼如下:

//安全過濾輸入[jb]
function check_str($string, $isurl = false)
{
$string = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]/','',$string);
$string = str_replace(array("\0","%00","\r"),'',$string);
empty($isurl) && $string = preg_replace("/&(?!(#[0-9]+|[a-z]+);)/si",'&',$string);
$string = str_replace(array("%3C",'<'),'<',$string);
$string = str_replace(array("%3E",'>'),'>',$string);
$string = str_replace(array('"',"'","\t",' '),array('“','‘',' ',' '),$string);
return trim($string);
}


下面是為大家整理的一些過濾函數(shù):

復(fù)制代碼 代碼如下:

/**
* 安全過濾類-過濾javascript,css,iframes,object等不安全參數(shù) 過濾級別高
*  Controller中使用方法:$this->controller->fliter_script($value)
* @param  string $value 需要過濾的值
* @return string
*/
function fliter_script($value) {
$value = preg_replace("/(javascript:)?on(click|load|key|mouse|error|abort|move|unload|change|dblclick|move|reset|resize|submit)/i","&111n\\2",$value);
$value = preg_replace("/(.*?)<\/script>/si","",$value);
$value = preg_replace("/(.*?)<\/iframe>/si","",$value);
$value = preg_replace ("http://iesU", '', $value);
return $value;
}

/**
* 安全過濾類-過濾HTML標簽
*  Controller中使用方法:$this->controller->fliter_html($value)
* @param  string $value 需要過濾的值
* @return string
*/
function fliter_html($value) {
if (function_exists('htmlspecialchars')) return htmlspecialchars($value);
return str_replace(array("&", '"', "'", "<", ">"), array("&", "\"", "'", "<", ">"), $value);
}

/**
* 安全過濾類-對進入的數(shù)據(jù)加下劃線 防止SQL注入
*  Controller中使用方法:$this->controller->fliter_sql($value)
* @param  string $value 需要過濾的值
* @return string
*/
function fliter_sql($value) {
$sql = array("select", 'insert', "update", "delete", "\'", "\/\*",
     "\.\.\/", "\.\/", "union", "into", "load_file", "outfile");
$sql_re = array("","","","","","","","","","","","");
return str_replace($sql, $sql_re, $value);
}

/**
* 安全過濾類-通用數(shù)據(jù)過濾
*  Controller中使用方法:$this->controller->fliter_escape($value)
* @param string $value 需要過濾的變量
* @return string|array
*/
function fliter_escape($value) {
if (is_array($value)) {
  foreach ($value as $k => $v) {
   $value[$k] = self::fliter_str($v);
  }
} else {
  $value = self::fliter_str($value);
}
return $value;
}

/**
* 安全過濾類-字符串過濾 過濾特殊有危害字符
*  Controller中使用方法:$this->controller->fliter_str($value)
* @param  string $value 需要過濾的值
* @return string
*/
function fliter_str($value) {
$badstr = array("\0", "%00", "\r", '&', ' ', '"', "'", "<", ">", "   ", "%3C", "%3E");
$newstr = array('', '', '', '&', ' ', '"', ''', "<", ">", "   ", "<", ">");
$value  = str_replace($badstr, $newstr, $value);
$value  = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $value);
return $value;
}

/**
* 私有路勁安全轉(zhuǎn)化
*  Controller中使用方法:$this->controller->filter_dir($fileName)
* @param string $fileName
* @return string
*/
function filter_dir($fileName) {
$tmpname = strtolower($fileName);
$temp = array(':/',"\0", "..");
if (str_replace($temp, '', $tmpname) !== $tmpname) {
  return false;
}
return $fileName;
}

/**
* 過濾目錄
*  Controller中使用方法:$this->controller->filter_path($path)
* @param string $path
* @return array
*/
public function filter_path($path) {
$path = str_replace(array("'",'#','=','`','$','%','&',';'), '', $path);
return rtrim(preg_replace('/(\/){2,}|(\\\){1,}/', '/', $path), '/');
}

/**
* 過濾PHP標簽
*  Controller中使用方法:$this->controller->filter_phptag($string)
* @param string $string
* @return string
*/
public function filter_phptag($string) {
return str_replace(array(''), array('<?', '?>'), $string);
}

/**
* 安全過濾類-返回函數(shù)
*  Controller中使用方法:$this->controller->str_out($value)
* @param  string $value 需要過濾的值
* @return string
*/
public function str_out($value) {
$badstr = array("<", ">", "%3C", "%3E");
$newstr = array("<", ">", "<", ">");
$value  = str_replace($newstr, $badstr, $value);
return stripslashes($value); //下劃線
}

相關(guān)文章

最新評論

兴国县| 北碚区| 蕲春县| 广灵县| 德庆县| 县级市| 灌云县| 堆龙德庆县| 会昌县| 云霄县| 扎兰屯市| 和林格尔县| 疏勒县| 绵竹市| 克拉玛依市| 敖汉旗| 遵义市| 若羌县| 信丰县| 河源市| 通江县| 磐安县| 金平| 赣州市| 镇坪县| 吉安县| 开化县| 舒城县| 富裕县| 全南县| 莱阳市| 金平| 伊金霍洛旗| 金门县| 运城市| 枣阳市| 沙坪坝区| 长宁区| 昌平区| 普格县| 诏安县|