Get the document root path in php $_SERVER['DOCUMENT_ROOT']

I ususally use this one if i am linking to files in the server document root folder rather than specifying ../directory/include.file.php i will use something like this: 

$document_root = $_SERVER['DOCUMENT_ROOT'];

Then you can use it in a require or include statement, or just echo it if you want to see what it is. 

include_once($document_root . "/inc/my.file.php");

or just use it inline

include_once($_SERVER['DOCUMENT_ROOT'] . "/inc/my.file.php");

the reason i would use this is so that in a large directory structure site you will always still be referring to the document root. ;)

Other Items in php
Page Views

This page has been viewed 273 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
time you enjoyed wasting is not wasted time