I put an empty php file in my root called root.php and included it on a page above the header using the absolute path. I then put $root = dirname("root.php"); at the top of my header and created my links based off of that but get nothing. I tried just echoing dirname("root.php") and got no output. I am I doing something wrong here?
Main Topics
Browse All Topics





by: Hube02Posted on 2009-11-04 at 19:23:01ID: 25746508
I think I know what you are looking for, and I can only think of one way to know what the site root might be if it can be anywhere and the links depend on knowing where it is installed.
You need to include a file in what the root of the site would be. I am assuming that php includes with relative paths will work, if not then there is no way at all that I know of to do this.
At anyrate, the top of all of your files would include
require('config.php'); or require('../config.php') or something on these lines.
A file always knows where it is located, even if you don't.
dirname(__FILE__) will give you the path to the folder that the config file is in and then you can set a contant based on this location:
define('DOC_ROOT', dirname(__FILE__));
However, like I said, this would require relative paths in php to work, meaning the file structure of you application would need to be constant within whatever folder or directory the user installs it.