PHP Filter Security filter function
PHP uses the parameters written by the filter extension to handle static classes, welcome to use.
I hope you have a good time and use it with confidence.
* */abstract Class cfilter{/** * type * @var array */public static $varType = Array (' GET ' = = input_get, ' POST ' = = Input_ POST, ' COOKIE ' = Input_cookie, ' SERVER ' = input_server, ' ENV ' = input_env);p ublic static $filterType = Array (' STRING ' =>filter_sanitize_string, ' INT ' =>filter_validate_int, ' BOOLEAN ' =>filter_validate_boolean, ' FLOAT ' =>filter_validate_float, ' REGEXP ' =>filter_validate_regexp, ' URL ' =>filter_validate_url, ' EMAIL ' = Filter_validate_email, ' IP ' =>filter_validate_ip,); /** * Support Filter list */private static function lists () {return filter_list ();}/** * Authentication type * @param string $type */public static Fun Ction FilterType ($type) {$filter _list = self::lists (); return Array_search ($type, $filter _list)!== false? True:false;}/ * * * @param $setVarType */private static function Getvartype ($setVarType) {$setVarType = Strtoupper ($setVarType); return Isset (self:: $varType [$setVarType])? Self:: $varType [$setVarType]: null;} /** * * @param string $setFilterType */private static FuNction Getfiltertype ($setFilterType) {$setFilterType = Strtoupper ($setFilterType); return Isset (self:: $filterType [$ Setfiltertype])? Self:: $filterType [$setFilterType]: null;} /** * Detects if the parameter exists * @param string $setVarType * @param string $varName */public static function varexists ($setVarType, $varNam E) {$FilterVarType = Self::getvartype ($setVarType), if (Is_null ($FilterVarType)) return False;return Filter_has_var ( Self:: $varType [$FilterVarType], $varName);} /** * * @param string $setVarType * @param string $varName * @param string $filterType */public static function Filterinpu T ($setVarType, $varName, $filterType = ' INT ') {$FilterVarType = Self::getvartype ($setVarType); $filterType = self:: Getfiltertype ($filterType); if (Is_null ($FilterVarType) | | is_null ($FILTERTYPE)) return False;return Filter_input ($ Filtervartype, $varName, $filterType);} /** * Validate variable * @param string $var * @param string $filterType */public static function Filtervar ($var, $filterType) {$filterTy PE = self::getfiltertype ($filterType); return Filter_var ($var, $filterType);} /** * String * @param string $var */public static function string ($var) {return Self::filtervar ($var, ' string ');} public static function Int ($var) {return Self::filtervar ($var, ' Int ');} public static function Boolean ($var) {return Self::filtervar ($ var, ' INT ');} public static function Float ($var) {return Self::filtervar ($var, ' Float ');}/** * * @param string $var * @param array $optio N Array ("Options" =>array ("regexp" = "/^m (. *)/")) */public static function RegExp ($var, $option) {$filterType = Self::getfiltertype ($filterType); return Filter_var ($var, $filterType, $option);} public static function Url ($var) {return Self::filtervar ($var, ' Url '), "public static function" Email ($var) {return self:: Filtervar ($var, ' EMAIL ');} public static function Ip ($var) {return Self::filtervar ($var, ' Ip ');}}
?
Reference Address: http://www.php.net/manual/en/book.filter.php
Source:Martin Blog [http://www.blags.org/]
This article link address:? http://www.blags.org/php-security-filter-function/