Includes are always relative to the working directory (actually, relative to the PATH, of which the working directory is a part). The working directory is determined by the script that's being executed. Say you have this structure:
webroot/
foo.php
folder/
bar.php
When you run foo.php
either through $ php foo.php
on the command line or by visiting localhost/foo.php
in your browser, the working directory is webroot/
. If you run folder/bar.php
, the working directory is webroot/folder
.
To make sure you're including files relative to the file the include
is in, use something like:
include __DIR__ . '/folder/bar.php`;
That, or alter your PATH to add your project root to it and always include relative to the project root. I prefer either file relative includes as shown above or autoloading though.