470,848 Members | 1,587 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

use of $_SERVER['DOCUMENT_ROOT'].

I'm working on a large intranet group site with a lot of pages, file types,
folders, subfolders, etc. I am using the include ('../includes/file.php') ,
but I would like to have a single snippet that will work for all .php/.html
pages in all subfolders. I have seen the $_SERVER['DOCUMENT_ROOT']
indicated as a way to access the root of the website without using ../ for
each folder you have to pass up through. However, I cannot get this to work
for me. I've seen recommendations for it's use in FAQs, etc. online, they
all seem to be a little bit different, but none of the formats (assign to a
variable, etc.) work for me. We're using PHP 4.3.2

Can someone give me some guidance on the use of this?

Thanks,
Chris

May 10 '06 #1
4 15990
Chris wrote:
I'm working on a large intranet group site with a lot of pages, file types,
folders, subfolders, etc. I am using the include ('../includes/file.php') ,
but I would like to have a single snippet that will work for all .php/.html
pages in all subfolders. I have seen the $_SERVER['DOCUMENT_ROOT']
indicated as a way to access the root of the website without using ../ for
each folder you have to pass up through. However, I cannot get this to work
for me. I've seen recommendations for it's use in FAQs, etc. online, they
all seem to be a little bit different, but none of the formats (assign to a
variable, etc.) work for me. We're using PHP 4.3.2

Can someone give me some guidance on the use of this?

Thanks,
Chris


Chris,

What webserver are you using?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 10 '06 #2
On Tue, 09 May 2006 12:06:06 -0700, Chris wrote:
I'm working on a large intranet group site with a lot of pages, file
types, folders, subfolders, etc. I am using the include
('../includes/file.php') , but I would like to have a single snippet that
will work for all .php/.html pages in all subfolders. I have seen the
$_SERVER['DOCUMENT_ROOT'] indicated as a way to access the root of the
website without using ../ for each folder you have to pass up through.


How about I give you a different way... In your Apache VirtualHost use:

php_value include_path .:/path/to/webroot/parent/includes/

Then you can just use:

include("file.php");

From anywhere and it will include it from the current folder (if found),
if not look in your /includes folder for it.

Anyway, you can do it by parsing $_SERVER["DOCUMENT_ROOT"] to get to the
parent, but it's much easier (and cleaner to read) by re-setting
include_path.

If you want to keep the current path you could do it using a single global
file which ini_set's the include_path to include the current include_path
and the new /includes folder. You could include that in your Apache
virtualhost using:

php_value auto_prepend_file /path/to/webroot/parent/includes/global.php

Hope this helps.

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 10 '06 #3
Thank you Andy. We're not using Apache...the current system is Linux, but
they have given me a Windows 2003 Server for a testing server. It just
seems to think of the document_root as the current folder that the document
resides in. Is there a change I need to make in the php.ini file?

Chris

"Andy Jeffries" <ne**@andyjeffries.co.uk> wrote in message
news:pa***************************@andyjeffries.co .uk...
On Tue, 09 May 2006 12:06:06 -0700, Chris wrote:
I'm working on a large intranet group site with a lot of pages, file
types, folders, subfolders, etc. I am using the include
('../includes/file.php') , but I would like to have a single snippet that
will work for all .php/.html pages in all subfolders. I have seen the
$_SERVER['DOCUMENT_ROOT'] indicated as a way to access the root of the
website without using ../ for each folder you have to pass up through.


How about I give you a different way... In your Apache VirtualHost use:

php_value include_path .:/path/to/webroot/parent/includes/

Then you can just use:

include("file.php");

From anywhere and it will include it from the current folder (if found),
if not look in your /includes folder for it.

Anyway, you can do it by parsing $_SERVER["DOCUMENT_ROOT"] to get to the
parent, but it's much easier (and cleaner to read) by re-setting
include_path.

If you want to keep the current path you could do it using a single global
file which ini_set's the include_path to include the current include_path
and the new /includes folder. You could include that in your Apache
virtualhost using:

php_value auto_prepend_file /path/to/webroot/parent/includes/global.php

Hope this helps.

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 10 '06 #4
Chris wrote:
Thank you Andy. We're not using Apache...the current system is Linux, but
they have given me a Windows 2003 Server for a testing server. It just
seems to think of the document_root as the current folder that the document
resides in. Is there a change I need to make in the php.ini file?

Chris

"Andy Jeffries" <ne**@andyjeffries.co.uk> wrote in message
news:pa***************************@andyjeffries.co .uk...
On Tue, 09 May 2006 12:06:06 -0700, Chris wrote:
I'm working on a large intranet group site with a lot of pages, file
types, folders, subfolders, etc. I am using the include
('../includes/file.php') , but I would like to have a single snippet that
will work for all .php/.html pages in all subfolders. I have seen the
$_SERVER['DOCUMENT_ROOT'] indicated as a way to access the root of the
website without using ../ for each folder you have to pass up through.


How about I give you a different way... In your Apache VirtualHost use:

php_value include_path .:/path/to/webroot/parent/includes/

Then you can just use:

include("file.php");

From anywhere and it will include it from the current folder (if found),
if not look in your /includes folder for it.

Anyway, you can do it by parsing $_SERVER["DOCUMENT_ROOT"] to get to the
parent, but it's much easier (and cleaner to read) by re-setting
include_path.

If you want to keep the current path you could do it using a single global
file which ini_set's the include_path to include the current include_path
and the new /includes folder. You could include that in your Apache
virtualhost using:

php_value auto_prepend_file /path/to/webroot/parent/includes/global.php

Hope this helps.

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos



Chris,

That's interesting.

I just created a file containing <?php phpinfo(); ?> in the root directory of my
IIS test machine. It shows $_SERVER['DOCUMENT_ROOT'] to be the path to the root
directory of my website - as expected.

Then I moved the file to a subdirectory (actually tried three different ones at
different levels). In each case phpinfo showed the document root to be the root
of the website.

This happens to be Windows 2000 instead of Windows 2003. PHP is loaded as an
isapi module (which does make a difference).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Tom | last post: by
2 posts views Thread by George Zervakos | last post: by
4 posts views Thread by Ronald Raygun | last post: by
6 posts views Thread by Jeff | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.