PHP get URI parts of URL
Look into parse_url()
. That will get you most of the way there. All you would need to do is remove the portion of the path that is part of your base URL.
print_r(parse_url('http://localhost/project/controller/action/param1/param2'));Array( [scheme] => http [host] => localhost [path] => /project/controller/action/param1/param2)
A more complete Example:
var_dump(parse_url(http://lambo-car-dealer.com/Lambo/All+Models/2018/?limits=10&advance_options=no));
output:
array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(48) "lambo-car-dealer.com" ["path"]=> string(44) "/Lambo/All+Models/2018/" ["query"]=> string(121) "limits=10&advance_options=no"
}
Also can get it this way:
$URL = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";$URI = "$_SERVER[REQUEST_URI]";