Reputation: 849
On the website I'm administrating, I use several include
and require
. I would like to define the entire structure of the website in some config-file that is included on each page so I don't have to worry about paths any more and no matter where the file is located, include('any_filename.php');
will always work.
I'd like to add that the site is on a shared host and I don't have full control of absolute paths or any .ini-file. The directory structure looks like this:
myDomainName.com
|
+-public_html
|
+-pictures
|
+-include
|
+-templates
where myDomainName.com is as high as I can go.
Or is there a smarter way to go?
Upvotes: 1
Views: 88
Reputation: 174967
The best way I can think of is to have a constant containing your base directory:
define("BASE_DIR", "/myDomainName.com/public_html/");
And have all subsequent files to include in the form of:
include BASE_DIR . "any_file.php";
If your PHP version is above 4.3.0 (very likely), you could also use set_include_path()
Upvotes: 1