I need to include the same file (navigation.php) from differing directories and file path structures. for instance i need to dynamically change the file depth eg:
include '../../../navigation.php';
and
include '../../../../../navigation.php';
need to be the same file (navigation.php).
furthermore i need to store the absolute path to (navigation.php)'s css and javascript files in a variable that would be the same throughout all directories of my website as mentioned before. for example in the cases where the following are true:
<link rel="stylesheet" href="../css/main.css">
and
<link rel="stylesheet" href="../../../css/main.css">
both directory paths would need to be referenced by one variable like this
<link rel="stylesheet" href="<?php echo $rootpath; ?>/css/main.css">
I have tried to use <?php echo " ".realpath($_SERVER["DOCUMENT_ROOT"])."/path/to/root/"
however this does not seem to work as i end up getting a path that looks like this
C:\before\root/path/to/root.
What would be the most effective way of making a standard dynamic variable that would indicate the path relative to the current folder or how could I fix the current problem I am having with absolute paths?