Page 1 of 1

default include directory

Posted: Fri Jun 16, 2006 6:35 am
by phpdevuk
Hello,
I'm building a website with files in many different folders, I want all folder to access the config file and class files from one directory at the top level of my directory structure. I've been looking for a way to do it with out changing my path in my scripts, so I'd like to just include 'inc/config.php' anywhere and for it to go to my inc directory regardless of if my script is in the website root or 5 directories down. I'm thinking some kind of .htaccess thing would do this, but I'm stumped. Any ideas?

Posted: Fri Jun 16, 2006 6:42 am
by Chris Corbyn
.htaccess is going to be fairly irrelevant for PHP's handle on the filesystem. I thought there was a php.ini directive to set the default include path.

In any case a you can use a config script yes that defines the absolute path to the application. You don't even have to modify that each time you move the code if you do this:

Code: Select all

define('APP_ROOT', dirname(__FILE__));
If this is for including classes when you need them then in PHP5 you have __autoload() to do this for you. I was going to look at a way to emulate __autoload() in PHP4 but haven't had time and I'm not sure it possible to do in a way that works the same.

Posted: Fri Jun 16, 2006 6:59 am
by phpdevuk
thanks, that is the sort of thing I am looking for. My host runs PHP5 thankfully so maybe I can use the autoload function.