Reputation: 1157
I use this PHP code for find the url path of a script page :
define("URL", dirname($_SERVER['REQUEST_URI']));
On my PC 1, I get this result with this url : htt://site1/abc/ :
/abc
but on my PC 2, I get this result with the same URL :
\
Don't understand why. If i add 'index.php', that's ok on PC 2
My goal is create a wizard installation and put the url path in the config file.
Upvotes: 1
Views: 104
Reputation: 42083
You may get unexpected results with dirname()
, see the example in the manual:
echo "2) " . dirname("/etc/") . PHP_EOL; // 2) / (or \ on Windows)
Use parse_url()
instead:
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$path = '/'.implode('/', explode('/', ltrim($path, '/'), -1));
define("URL", $path);
Upvotes: 1