I'm filtering $_SERVER["REQUEST_URI"] such that:
$_request_uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL);
As explained in php.net:
FILTER_SANITIZE_URL
Remove all characters except letters, digits and $-_.+!*'(),{}|\^~[]`<>#%";/?:@&=.
However,
the browser sends this REQUEST_URI value urlencode'd and therefore it is not sanitized in this filter_input() function. Say the address is
and then the sanitized request url is
/abc/index.php?q=abc%EF%BF%BD%EF%BF%BD123
But it should be
/abc/index.php?q=abc123
It is possible urldecode($_SERVER["REQUEST_URI"]) and then using filter_var() we can get a sanitized value.
$_request_uri = filter_var(urldecode($_SERVER['REQUEST_URI']), FILTER_SANITIZE_URL);
I don't know why the last one seems to me "inelegant" and I'm looking for an elegant way, sanitizing $_SERVER["REQUEST_URI"].
Maybe, accessing a super global array directly ($_SERVER['REQUEST_URI']) while coding disturbs me, thus "inelegant".
Is there an elegant way?