PHP: using $SERVER[] to return the current directory, regardless of "nice urls"
I am trying to return the current directory of a file in php, regardless what it says in the browser bar. I have tried:
echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
If the url is
http://example.com/directory1/directory2/var1/var2/var3
the above code returns
example.com/directory1/directory2/var1/var2/var3
even though var1/var2/var3 are GET_[]
variables tamed by a htaccess RewriteRule. Is there a decent way to get the directory? in the case above开发者_StackOverflow社区 I would like to return:
example.com/directory1/directory2/
thanks.
How about replace it with SCRIPT_FILENAME
?
str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME']));
精彩评论