Skip to content

Instantly share code, notes, and snippets.

@zhangguiqiang
Created June 2, 2012 16:29
Show Gist options
  • Save zhangguiqiang/2859060 to your computer and use it in GitHub Desktop.
Save zhangguiqiang/2859060 to your computer and use it in GitHub Desktop.
格式化数据-防止注入
//格式化数据(防止注入)
function site_addslashes($string, $force = 0) {
!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
if(!MAGIC_QUOTES_GPC || $force) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment