473,324 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 16107
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom | last post by:
I'm trying to dynamically adjust the path for one of my scripts using this: $script_path = str_replace( $_SERVER, "", dirname(realpath(__FILE__)) ) . DIRECTORY_SEPARATOR; The problem: the...
2
by: George Zervakos | last post by:
Hello, I'm new to php and was wondering if someone could help me out with the best way to accomplish this. I have Solaris 9/Apache 1.3.31/PHP 5.1.4 that I compiled from source code and...
12
by: comp.lang.php | last post by:
Env: Windows XP, Apache 1.33, PHP 5.2.0 <? echo is_dir($_SERVER) . " for dir = " . $_SERVER); ?>
4
by: Ronald Raygun | last post by:
I have just discovered that the value reported for $_SERVER by phpinfo is different from the value I obtain when I run the following: <?php echo $_SERVER ?> My natural assumption is to assume...
6
by: Jeff | last post by:
Is $_SERVER alway available? I ask this because I've seen on windows that the perl equivalent was missing. Is this settable and accessible the same way (ie not having to use global)? Jeff
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.