Forum Moderators: coopster
[cgi101.com...]
I think you are wanting the PATH variable, so using dreamcatcher's example...
$server = $_SERVER['PATH'];
echo $server;
Jordan
<?php
$svr = $_SERVER['SCRIPT_NAME'];
function getRoot($root, $svr) {
if ($root!= $svr) {
$root = $svr;
$svr = preg_replace('/(\/.+\/?)/', "$2", $svr);
if ($root!= $svr) {
getRoot($root, $svr);
}
else {
echo $root . '/';
}
}
}
getRoot("", $svr);
?>
You can also try it with...
$svr = $_SERVER['SCRIPT_FILENAME'];
or
$svr = $_SERVER['REQUEST_URI'];
Mabye one of those will work...
Jordan
f:\users\l\lindajames\user\htdocs\index.php
can i not get the script to not display everything after the htdocs?
$_SERVER['DOCUMENT_ROOT']
that's right and will return the value of the DocumentRoot for the given site from apache.
[httpd.apache.org...]
in this particular case I am thinking you need too look at the apache conf and see what that says.
$_SERVER['DOCUMENT_ROOT'] works, isnt there anyway to actually use that but get the php code to get rid of the final part of the path which has the actual file name
...yes, easiest is probably preg_replace(), something like...
$server = preg_replace('/(.+\/).+\..+/', "$1", $_SERVER['DOCUMENT_ROOT']);
echo $server;
Jordan
I use $_SERVER['DOCUMENT_ROOT'] *all* the time and it gets me just what I want. The directory for the root of the virtualserver that I'm on.
By any change are you running IIS rather than apache on windows? As I remember IIS does not set a DOCUMENT_ROOT this is an apache thing. I remember it giving me some heart ache when I had to do work work on an IIS server.
daisho.