- 論壇徽章:
- 0
|
較早時(shí)候?qū)懙倪^濾函數(shù),只需要在數(shù)據(jù)使用之前調(diào)用filter_input()即可,
可用于$_GET, $_POST, $_REQUEST, $_COOKIE,
直接修改它們,無返回值,
首參為要過濾的關(guān)鍵字,可為null(全部),字符串,數(shù)組,
二參是要過濾的數(shù)組,1 - get, 2 - post, 4 - request, 8 - cookie,可以做或運(yùn)算。
function filter_input($keys = NULL, $type = 7) {
if(get_magic_quotes_gpc()) return;
// type: 1 - get, 2 - post, 4 - request, 8 - cookie
$cos = array();
if($type & 1) $cos[] =& $_GET;
if($type & 2) $cos[] =& $_POST;
if($type & 4) $cos[] =& $_REQUEST;
if($type & 8) $cos[] =& $_COOKIE;
foreach($cos as &$cv) {
if(empty($keys)) foreach($cv as &$v) filter_real($v);
else if(!is_array($keys)) filter_real($cv[$keys]);
else foreach($keys as &$k) filter_real($cv[$k]);
}
}
function filter_real(&$v) {
if(is_array($v)) foreach($v as &$v2) filter_real($v2);
else if(!is_string($v)) return;
$v = addslashes($v);
}
本文來自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u1/57558/showart_1072668.html |
|