较早时候写的过滤函数,只需要在数据使用之前调用filter_input()即可,
可用于$_GET, $_POST, $_REQUEST, $_COOKIE,
直接修改它们,无返回值,
首参为要过滤的关键字,可为null(全部),字符串,数组,
二参是要过滤的数组,
1 - get, 2 - post, 4 - request, 8 - cookie,可以做或运算。
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);
}
|
阅读(1709) | 评论(0) | 转发(0) |