Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: using $SERVER[] to return the current directory, regardless of "nice urls"

Tags:

php

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 I would like to return:

example.com/directory1/directory2/

thanks.

like image 821
superUntitled Avatar asked Jan 07 '11 05:01

superUntitled


1 Answers

How about replace it with SCRIPT_FILENAME ?

str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME']));
like image 117
ajreal Avatar answered Oct 21 '22 12:10

ajreal