Page 1 of 1

Variable for returning the script's path w/out script name

Posted: Wed Feb 09, 2005 1:47 pm
by sethpackham
I need a way to return the path of the current script, as opposed to the script name. Is there a $_SERVER or other variable for doing this? I need to do some IF-ELSE statements based on the path of a set of scripts, not the script names themselves.

For example, if I'm running a script at /home/user/www/domain.com/addresses/addresses.php, I need some sort of variable that returns the following:

/home/user/www/domain.com/addresses

Code: Select all

$_SERVERї'PHP_SELF']; //This returns the script name, not the root dir of the script
$_SERVERї'DOCUMENT_ROOT']; //this returns the root of the domain, not the root of the current script
$_SERVERї'SCRIPT_NAME']; //This returns the script name
$_SERVERї'PATH_TRANSLATED']; //This returns the full server path, including the script
Any ideas are appreciated.

Posted: Wed Feb 09, 2005 1:57 pm
by feyd
dirname() with path_translated..

Posted: Wed Feb 09, 2005 2:05 pm
by sethpackham
Thanks for the pointer.

dirname() is exactly what I needed.