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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sethpackham
Forum Newbie
Posts: 11
Joined: Fri Nov 07, 2003 3:28 pm
Location: Apex, NC

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

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

dirname() with path_translated..
sethpackham
Forum Newbie
Posts: 11
Joined: Fri Nov 07, 2003 3:28 pm
Location: Apex, NC

Post by sethpackham »

Thanks for the pointer.

dirname() is exactly what I needed.
Post Reply