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

2009-07-06 Thread Kim N. Lesmer
On Sun, 5 Jul 2009 14:33:07 -0600
Govinda govinda.webdnat...@gmail.com wrote:

 I am confusing myself reading the docs just now.
 
 i.e.:
 include_path
 basename()
 and dirname()
 
   I had thought from many months ago that
 ?php include '/somedir/somefile.php'; ?
 would include
 somefile.php
 living in
 somedir
 regardless from where in the site structure I am calling it.
 
 Now it does not seem to be doing that.
 
 What is the safest (portable) way to properly build an include path  
 *regardless* from where in my site I am calling the include?
 If I understand right I can put includes in a dir/ specified by the  
 include_path setting, but I also want to know how to do this from
 just within the root of my virtual server.

Like Michael said there is more than one way to deal with this.

I personally prefer to use this:

require_once ($_SERVER['DOCUMENT_ROOT'] . /incl/myfile.php);

Unless the file needs to be kept outside of where the webserver serves
files.

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


---
Mange venlige hilsner/Best regards

Kim Naim Lesmer
Programmer/Unix systemadministrator

Web: www.bitflop.com
E-mail : k...@bitflop.com


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



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

2009-07-06 Thread Kim N. Lesmer
On Mon, 6 Jul 2009 16:16:55 -0600
Govinda govinda.webdnat...@gmail.com 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 : k...@bitflop.com


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