title: can server document root be relied upon
body: <p>I wrote the PHP code for my website almost 9 years ago. I have a config file called <code>common.php</code>. Each page in my site requires this page to access the site's constants, classes and variables.</p>
  
  <p>I develop on a local machine and then upload files to a live site. The code I have used on my pages to call <code>common.php</code> is:</p>
  
  <pre><code>$main = ($_SERVER['HTTP_HOST'] == 'localhost')? "E:\-=Web=-\-=Sites=-\mysite\main\common.php" :"/home/mysite/public_html/main/common.php";
  require_once($main);
  </code></pre>
  
  <p>This has worked fine and has never given me any issues.</p>
  
  <p>However, I figure I could instead just use:</p>
  
  <pre><code>require_once($_SERVER["DOCUMENT_ROOT"]."/main/common.php")
  </code></pre>
  
  <p>This would make my code more compact and it also means I do not have to have my development site files always in <code>E://</code></p>
  
  <p>So my question is, is it good practice to use <code>$_SERVER["DOCUMENT_ROOT"]</code>?</p>
  
  <p>Is this what most developers would do if wishing to call the config file on each page?</p>