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?
default include directory
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
.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:
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.
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__));