Re: Getting the right path output from $_SERVER

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dave M G wrote:
PHP General,

What I am trying to achieve is to output the path in which the current script is executing, without having the name of the file attached. I'm hoping to be able to do this without complicated code to truncate path names and whatnot.

Either of these two variables do what I want, except that they include the name of the file:

$_SERVER[PHP_SELF]
$_SERVER[SCRIPT_NAME]

For example, if create file called "test.php" and I echo the output of $_SERVER[PHP_SELF], I get:
/web_sites/gutteridge.info/web/test.php

But all I want is:
/web_sites/gutteridge.info/web

(It's important that the last forward slash not be there).

I would have thought that an existing global variable would exist to do this, but I can't find it in the php manual:
http://www.php.net/manual/en/reserved.variables.php

$_SERVER[DOCUMENT_ROOT] provides a path without the file name, but it's not the path I need. In my case, the output is:
/var/www

$_SERVER[PATH_TRANSLATED] also provides a different path, and also attaches the file name:
/var/www/web_sites/gutteridge.info/web/test.php

The bottom line is, how can I get the same path as $_SERVER[PHP_SELF] or $_SERVER[SCRIPT_NAME], but without including the file name?

use dirname().

http://www.php.net/dirname

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux