Is it a good idea to use $_SERVER['DOCUMENT_ROOT'] in includes?
<p>Is this, for example, a good idea?</p>

<pre><code>require_once($_SERVER['DOCUMENT_ROOT'].'/include.php');
</code></pre>

<p>If you have two virtual hosts on the same server, one for live and one for development, with different Apache DocumentRoots, this would avoid having to include absolute paths when the source of the include is unknown, and may be in any directory.</p>

<p>(Note: file paths in the following section are relative to the web root. They would in fact be like /var/www/app/core/init.php, where /var/www/app is the web root)</p>

<p>For instance: I have an /core/init.php which is called using relative paths from places all over the website (/file.php, /dir/file.php or /dir/dir/file.php). </p>

<p>This init.php then includes several function pages, in the func directory, a subdir of /core (as in /core/func/userfunctions.php).</p>

<p>So, in init.php, I can use the $_SERVER method, because it breaks if I use a relative path and try to call functions from a page like /dir/file.php.</p>

<p>I can't see any problem with it, but in general what could go wrong?</p>
