what is a good method to sanitize the whole $_POST array in php?

后端 未结 5 1158
广开言路
广开言路 2020-12-12 21:08

I have a form with a lot of variables which is then sending an email, rather than sanitizing each $_POST value with filter_var($_POST[\'var\'], FILTER_SAN

5条回答
  •  旧巷少年郎
    2020-12-12 21:25

    This is what I use in all my projects:

    function util_array_trim(array &$array, $filter = false)
    {
        array_walk_recursive($array, function (&$value) use ($filter) {
            $value = trim($value);
            if ($filter) {
                $value = filter_var($value, FILTER_SANITIZE_STRING);
            }
        });
    
        return $array;
    }
    

    It allows to trim and sanitize a nested array of posted data

提交回复
热议问题