Re: best way to properly build an include path *regardless* from where I am calling the include?

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

 



On Mon, 6 Jul 2009 16:16:55 -0600
Govinda <govinda.webdnatalk@xxxxxxxxx> wrote:

> I do not really understand why
> $_SERVER['DOCUMENT_ROOT']
> should return the right data at one time and not at another.  (?)

In general it will always provide the right data, but as the manual
says: "The entries in this array ($_SERVER) are created by the web
server. There is no guarantee that every web server will provide any of
these; servers may omit some."

The problem could arise if the script is transfered unto a web server
where the $_SERVER array (or parts of it - in this case the
document_root part) has been disabled.

Take into consideration where the script/program has to run and whether
it is likely to be moved around to different web servers with different
setups.

> Also, what is the difference between a path that starts with "/",  
> versus the same path but that does not have that leading "/", or
> that same path but prefixed with "./"?
>
> I.e., this:
> /somepath/includes/file.php

This depends on whether the web server is running in a chroot.

If the web server for example has access to all files on the machine
and isn't running in any kind of chroot or limited setup, then
"/somepath" is located in the very root of the directory on that
particular hard drive (or partition) and "/somepath" is NOT a sub
directory of another directory.

So you would see something like this (if you are not using Windows):

/var/www/mywebsite.com/
/somepath/includes/file.php
/usr/sbin/
/home/foo/

> versus this:
> somepath/includes/file.php

This depends on where your script is running from. 

If your script is running in: 
/var/www/mywebsite.com/myscript.php

Then the above would become:
/var/www/mywebsite.com/somepath/includes/file.php

If your script is running in: 
/var/www/mywebsite.com/subdirectory/myscript.php

Then the above would become:
/var/www/mywebsite.com/subdirectory/somepath/includes/file.php

> versus this:
> ./somepath/includes/file.php

Its the same as "somepath/includes/file.php" a "./" means "current
working directory".

I hope I make sense.

If you haven't already take a look at:
http://php.net/manual/en/function.include.php

> ("../" I know)
> 
> -G


---
Mange venlige hilsner/Best regards

Kim Naim Lesmer
Programmer/Unix systemadministrator

Web    : www.bitflop.com
E-mail : knl@xxxxxxxxxxx


-- 
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