Page 1 of 1

Question about Document Root

Posted: Tue Aug 19, 2008 3:20 pm
by SyntheticShield
I am in the process of redesigning my website and I decided I would take my time and try and learn a few things. One of the things I wanted to learn was at least some basic php. Long story short, Im trying to use includes for content, menus and such. And in that process, it occurred to me that I had seen an example in a book where they used includes to build the page template as well so I thought why not.

Well, in the process of doing this the more pages I created the harder it became to keep track of how many '../' was I going to have to use to get the links to refer to the points I wanted in the site structure. A google search lead me to

Code: Select all

$_SERVER['DOCUMENT_ROOT'];
Which in turn led me to the use of:

Code: Select all

<?php include ($_SERVER['DOCUMENT_ROOT'].'/file/location.php');
That in turn got me to thinking, but unable to find a solution thus far is how can I declare document root globally for the entire page so that I dont have to write for each include

Code: Select all

($_SERVER['DOCUMENT_ROOT']
? Im not sure it can be done, just asking and keep in mind Im new to all this but trying to learn. I guess Im just trying to make the code more efficient and Im not sure there would be any reason to declare such a thing just one time for the whole page.

Anyway, I'll stop there and see what I need to do or if there are any options. Thanks in advance for your help.

Re: Question about Document Root

Posted: Tue Aug 19, 2008 7:20 pm
by califdon
Well, you could certainly assign it to a variable and then use that variable (all you're after is a string, after all), but you probably wouldn't save much code by doing so. I think it is pretty common practice to just use the $_SERVER['DOCUMENT_ROOT'] expression where needed.

Re: Question about Document Root

Posted: Tue Aug 19, 2008 9:35 pm
by SyntheticShield
Understood. I figured it couldnt help but to check. Im sure I'll be around with other questions as I dive into this a bit more.