Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/9045018 to your computer and use it in GitHub Desktop.
Save james2doyle/9045018 to your computer and use it in GitHub Desktop.
Sanatize and filter $_GET and $_POST data that handles arrays and is recursive. http://goo.gl/Fonl6D
// Filters data against security risks.
function filter($data) {
if (is_array($data)) {
foreach ($data as $key => $element) {
$data[$key] = filter($element);
}
} else {
$data = trim(htmlentities(strip_tags($data)));
if(get_magic_quotes_gpc()) {
$data = stripslashes($data);
}
$data = filter_var($data ,FILTER_SANITIZE_STRING);
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment