php.ini file question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

In the inherited system, there are about 30 files, and each one
uses the include() with the absolute path, e.g.


I realize I can set the include_path in php.ini to

but I'm wondering if I can also set a new variable instead, e.g.


then in the code, I can write


yes, no, is there a better way? Or should I stick with the
php.ini include path?


Re: php.ini file question

blanche cohen wrote:
Quoted text here. Click to load it

The best way is to reference everything on your site relative to

   include($_SERVER['DOCUMENT_ROOT'] . '/');

This way is independent of the file system layout, and you load the one
you think you are.

include_path is good for extensions and other extras which are common to
the entire system (i.e. multiple websites on the same system or maybe in
different locations on different servers) such as the PEAR and PECL

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: php.ini file question

blanche cohen escribió:
Quoted text here. Click to load it

According to Murphy's Law, the app will probably have two or three files in different directories and relying on
include_path will make PHP load the wrong one. Also, I don't think PHP
scans subdirectories when looking for files.

Quoted text here. Click to load it

I personally prefer constants for such stuff: they are available
everywhere while global variables must be loaded explicitly from within
functions and classes. In fact, the base path is normally constant ;-)

I usually build a ROOT constant in my main settings file with the help
of dirname(__FILE__) and use it everywhere else. Of course, I can't use
it to include the settings file itself but there're many tricks: from
relative paths to playing around with $_SERVER['DOCUMENT_ROOT'].

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Site Timeline