过滤GET POST COOKIE
时间:2008-04-21 来源:liuxingyuyuni
?php
/**
* @desc Filter GPC variable
* @param String $allow_tags
* @param Array $protect_words
* @return Array $gpc
* */
function filterGpc($allow_tags='', $protect_words='') {
$gpc = array('get'=>$_GET, 'post'=>$_POST, 'cookie'=>$_COOKIE);
foreach($gpc as $k1=>$v1) {
foreach($v1 as $k2=>$v2) {
$v2 = get_magic_quotes_gpc() ? $v2 : addslashes($v2);
$v2 = trim($v2);
$v2 = nl2br($v2);
$v2 = strip_tags($v2, $allow_tags);
$gpc[$k1][$k2] = $v2;
if(! empty($protect_words)) {
foreach($protect_words as $word) {
if((strpos(strtolower($gpc[$k1][$k2]), $word) !== FALSE)) die("Hack!");
}
}
}
}
unset($_GET, $_POST, $_COOKIE);
return $gpc;
}
$allow_tags = "";
$protect_words = array('insert', 'update', 'delete', 'select', 'from', 'or');
$gpc = filterGpc($allow_tags, $protect_words);
?>
相关阅读 更多 +