Created
April 15, 2019 08:58
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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