自己常用的PHP方法

代码中发单位的一些代码,求喷,这样也可以让他们看到得以改进。

博客中发些自己的代码,也求喷,同时希望各类大牛们给上建议或意见


SQL注入的
function filter_slashes(&$value) {
	if (get_magic_quotes_gpc()) return false;
		$value = (array) $value;
		foreach ($value as $key => $val) {
			if (is_array($val)) {
				filter_slashes($value[$key]);
			} else {
				$value[$key] = addslashes($val);
		}
	}
}
function filter_sql($value) {
    $sql = array("select", 'insert', "update", "delete", "\'", "\/\*", 
                        "\.\.\/", "\.\/", "union", "into", "load_file", "
    $sql_re = array("","","","","","","","","","","","");
    return str_replace($sql, $sql_re, $value);
}
XSS
function filter_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(.*?)>(.*?)<\/script>/si","",$value);
	$value = preg_replace("/<iframe(.*?)>(.*?)<\/iframe>/si","",$value);
	$value = preg_replace ("/<object.+<\/object>/iesU", '', $value);
	return $value;
}


你可能感兴趣的:(自己常用的PHP方法)