So I set up my include files, such as
footer.php in a
Then I include the files in my pages. But if I have another folder, for example
wiki where i'd like to include those files onto the pages of wiki, the file paths for the includes break.
Example: I have included this in a page from the
<?php include_once('../inc/header.php'); ?>
I have two other includes in the header.php file, but since I'm including them in a different directory, both includes break, unless I go and append a
../ in the include path.
I'm wondering what is the best way to include files within different directories and not having to go back and fix the path?
Create constants using
realpath in the initial file and then reference them using easy to read and manage but now absolute paths.
You can see an example here:
How can I get the "application root" of my URL from PHP?
I'd also suggest testing for the constant definition before defining.