PATH_INFO does not show "extras"

0

I'm using $_SERVER["PATH_INFO"] to pass values to the backend through the url, other than ?chave=valor , instead, /:valor/ (I identify the colon and return a variable with that name) when I have a request for url //valor/ the value of $_SERVER["PATH_INFO"] is /valor/ , causing some problems ...

Why? And how to solve?

    
asked by anonymous 11.07.2018 / 22:32

1 answer

0

I solved the problem using $_SERVER["SCRIPT_NAME"] and $_SERVER["REQUEST_URI"] :

//Requisição para example.com/index.php/foo//bar/baz
$current_route = str_replace("/", "\/", $_SERVER["SCRIPT_NAME"]); // \/index.php"
$current_route = preg_replace("/(\.[a-z]*)/", "($1)?", $current_route); // \/index(.php)?
$current_route = preg_replace("/{$current_route}/", "", $_SERVER["REQUEST_URI"]); // /foo//bar/baz

The second line makes optional the .php extension because I hid it by .htaccess

    
03.09.2018 / 18:55