By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

Why put all includes in single Include file instead of within each site?

P: 6
HI,
Just a question out of curiosity - I'm running a few sites on one IP address in Apache, and every tutorial I've found says to put your Includes file in the PHP/Includes folder. However, I much prefer to have an includes file within each site folder that I've created and keep it all together. Can someone please explain if I'm misunderstanding something, or why you should set all includes up in one folder with subfolders??

Thanks!!

Maiya
May 18 '07 #1
Share this Question
Share on Google+
4 Replies


pbmods
Expert 5K+
P: 5,821
It's really up to you. I never use the global include directory (if I can even remember where I put it!); I define my include_path at runtime:

Expand|Select|Wrap|Line Numbers
  1. ini_set('include_path', ini_get('include_path') . ":$GLOBALS[PATH_PREFIX]/$GLOBALS[PATH_CORE]:$GLOBALS[PATH_PREFIX]/$GLOBALS[PATH_TEMPLATE]");
  2.  
Of course, I develop apps designed to be deployed to separate servers, so it doesn't really make any sense for me to use a global include directory.

On the other hand, if you had several projects, and you were going to serve them all from the same machine, it would save you some hard drive space if you only had to keep one copy of each redundant file. Plus, if you had to make changes to one of those files, you wouldn't have to worry about propagating the changes to six other copies (but then, you DO use version control, right?)

Incidentally, although this is not specific to the PHP/Includes folder, if you store include files outside your site root, they can't be accessed except via include (ok, and require) statements inside your code. E.g., you could store your MySQL login script here so that nobody could access it directly.
May 19 '07 #2

P: 6
thanks!! Sorry for my ignorance (i'm still very new at this) but do you have to put this code

ini_set('include_path', ini_get('include_path') . ":$GLOBALS[PATH_PREFIX]/$GLOBALS[PATH_CORE]:$GLOBALS[PATH_PREFIX]/$GLOBALS[PATH_TEMPLATE]");

at the beginning of each page, or is there a way to specify that all of your includes are in the (site root)/includes folder?
May 19 '07 #3

pbmods
Expert 5K+
P: 5,821
thanks!! Sorry for my ignorance (i'm still very new at this) but do you have to put this code

ini_set('include_path', ini_get('include_path') . ":$GLOBALS[PATH_PREFIX]/$GLOBALS[PATH_CORE]:$GLOBALS[PATH_PREFIX]/$GLOBALS[PATH_TEMPLATE]");

at the beginning of each page, or is there a way to specify that all of your includes are in the (site root)/includes folder?
I actually pulled this code out of my frameworks; none of those globals are defined by default. I store them in the database and then pull them at the start of script execution so I can keep my projects as portable as possible.

You'll probably want to use something like this:

Expand|Select|Wrap|Line Numbers
  1. ini_set('include_path', ini_get('include_path') . ":$_SERVER['DOCUMENT_ROOT']/Includes:$_SERVER['DOCUMENT_ROOT']/path/to/your/project/IncludesOrWhateverYouWantToCallIt");
  2.  
And so on. Just make sure that each item is separated by a ':' (you also need to separate the original include path [ini_get('include_path')] from your custom include path, hence the ':' at the start of the string as well).
May 19 '07 #4

P: 6
thanks so much!! I'll see how it goes..
May 24 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.