"Config" file included in every script

What’s the common practice here? Should I define constants in the “config” file with absolute paths for highly used directories/files of the project in order to easily modify include paths in the future?

Depends …

If it is for a distinct standalone application, lets say “acme_cms” I just add that folder beneath my includes directory (or directories), then do this:

include 'acme_cms/database.inc.php';

Then it does not matter how many directories deep my app goes, PHP always goes looking in the includes folder set in your php.ini file. That said I am on a dedicated server so have full control over my ini file.

Another “depends” might be if you plan on distributing your code, in which case the way you described might be more advisable as it is probably more portable.

The include_path directive can be set in a variety of ways though.

My include directory string resembles:

include_path “.\;\var\www\includes;\var\www\includes\PEAR;\var\www\includes\lib”

in my example then, acme would go here :


Then it would just wire itself up and work…

Likewise if I had a magic class in /lib that I wanted to use in the acme project I’d just access it like so

include 'magic.php'; // or magic.class.php if you prefer

Thanks for the reply Cups.

I’ve tried include_path on localhost and I find it a good solution, but I’m not sure if I can set include_path on a shared host.

This tells you which directive can be changed from where:

ini file
& possibly
apache config files
apache per directory .htaccess files
on the page using ini_set()


What consts like PHP_INI_ALL mean http://www.php.net/manual/en/configuration.changes.modes.php

Nice, it’s changeable everywhere.:slight_smile:

Some would say, Argghhh! its changeable everywhere!

ie try and stick to one place if you can – otherwise you will lose track of where it is being set.