I've looked around for an answer and hopefully I didn't miss it or am not repeating it but here it goes. I have two files:
/var/www/index.php
/var/www/include/php/header.php
Index includes the header.php
file. I want the header file to be able to traverse up two levels so I could include /include/css/index.css
. Here's the problem, The header is also included by files such as
/var/www/sub/page.php
so I cannot simply use ../../
since location of the php file changes. I tried using $_SERVER['PHP_SELF']
but that changes depending on the location of the php file that includes the header file. I also tried dirname(__FILE__)
but that gives me the /var/www/
part which cause complications for including.
Essentially I would like the value of $_SERVER['PHP_SELF']
from the included header.php
file and not from the php script that includes it. I want the site to be modular so it can be posted anywhere without having to worry about file locations getting messed up. Is there an easier way to do this?