There are two problems in your example.
$parts = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$_SERVER
is a super global array and HTTP_HOST
is one of it's indices. As this is an associative array you need to enclose the index name with a pair of either single quotes, or double quotes. So it should be $_SERVER['HTTP_HOST']
, and because this is inside a string you need to use {}
to interpolate the variable/array name. So it looks like:
$parts = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
or simply separate them as
$parts = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
Your second problem is:
$path_parts= explode('/', $parts[path]);
as far as your code goes $parts
is a string not an array, so $parts[path]
has no meaning here. It should be:
$path_parts= explode('/', $parts);