Skip to content

Instantly share code, notes, and snippets.

@Digi92
Created April 15, 2019 08:58
Show Gist options
  • Save Digi92/fceb88205b51d4a3b5cdf45270f5ea0b to your computer and use it in GitHub Desktop.
Save Digi92/fceb88205b51d4a3b5cdf45270f5ea0b to your computer and use it in GitHub Desktop.
This function will remove all suspicious characters from a $_GET parameter. This has only a security reason. Source: https://stackoverflow.com/a/1886296
/**
* This function will remove all suspicious characters from a $_GET parameter
*
* @param $url
* @return array|string|string[]|null
*/
protected function filterUrl($url)
{
if (is_array($url))
{
foreach ($url as $key => $value)
{
// recurssion
$url[$key] = $this->filterUrl($value);
}
return $url;
}
else
{
// remove everything except for a-zA-Z0-9_.-&=
$url = preg_replace('/[^a-zA-Z0-9_\.\-&=]/', '', $url);
return $url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment