note 11338 deleted from function.include by spic
| From: | spic@php.net | Date: | Wed, 28 Aug 2002 08:00:44 +0000 |
| Subject: | note 11338 deleted from function.include by spic | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-35854@lists.php.net to get a copy of this message | ||
When working with large PHP projects in a web farm or virtual hosting environment (where there are
many web sites on the same server and you can't gain access to the php.ini file), I've
developed a good method for keeping PHP includes and objects out of the web space, and allowing them
to be included nearly seemlessly:
First, you create a file like "constants.php" or something like that, and put that outside
of your web space. In this file, create some constants containing the paths to directories of
includes, such as:
static $OBJECT_PATH = "/home/meep/php/objects/";
static $HEADER_PATH = "/home/meep/php/includes/headers/";
then, on your individual PHP pages, you will need to include this constant file:
include "/home/meep/php/config/constants.php";
and you can then include individual files by:
include $GLOBALS["OBJECT_PATH"] . "myClass.php";
include $GLOBALS["HEADER_PATH"] . "blueHeader.php";
This solution seems to work well for me, and if I do eventually move things around, I will only need
to change the variable's value in the constants file. You can also include other site-wide
constants here, such as a site's name, etc., which you might use throughout the project.
Remember - hard-coding values is bad practice, and any sort of thought process to avoid hard-coding
things should be encouraged, even "hacks" like this one.
Happy hacking!