superUntitled superUntitled - 1 year ago 73
PHP Question

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:


If the url is

the above code returns

even though var1/var2/var3 are
variables tamed by a htaccess RewriteRule. Is there a decent way to get the directory? in the case above I would like to return:


Answer Source

How about replace it with SCRIPT_FILENAME ?

str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME']));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download