My root/index.php includes root/Pages/home.php, which has the following statement:
include(“header.php”);
The functionality of this include varies. If there’s a file located at root/header.php, that’s the file that gets included. Otherwise, it loads root/Pages/header.php, which is what I would expect to be the default behavior.
Can anyone explain what’s going on? I didn’t see any clear explanation in the documentation, but I can imagine it’s because the executed file (index.php) is in root rather than Pages.
Also, I suppose this means I take a tiny efficiency hit if I don’t use the full path?
i am also not 100% sure about the ?
but if question is (what i feel is)
root
header.php
folder1
header.php
file.php
and in file1 header of folder1 is included rather than header of root
then
using this
require_once($_SERVER[‘DOCUMENT_ROOT’].‘/header.php’);
can come handy
some use site_url config varibale but this is more generic i guess…
PHP is a computer.
Therefore, it does things in order.
When PHP reaches an Include statement, it tries to immediately access the file located in the parenthses, if it has a relative address (‘./filename.php’).
If it fails to find the file there or if the address is indeterminately relative, it starts at the beginning of it’s Include-Path (Divided up by the colons). 99.999999% of the time, that’s in “.” (Current Executing Directory). Then /php/includes (Or wherever the person points it.) and so on. If it reaches the end of the include_path configuration setting without finding the file, it throws an error and moves on. (Include failure is E_WARN level, whereas Require() failure is Fatal)