How to detect the path to the application root?
<p>I'm trying to dynamically detect the root directory of my page in order to direct to a specific script.</p>

<pre><code>echo ($_SERVER['DOCUMENT_ROOT']); 
</code></pre>

<p>It prints /myName/folder/index.php</p>

<p>I'd like to use in a html-file to enter a certain script like this:</p>

<pre><code>&lt;a href="&lt;?php $_SERVER['DOCUMENT_ROOT'].'lib/logout.php'?&gt;"&gt;log out&lt;/a&gt;
</code></pre>

<p>This seems to be in bad syntax, the path is not successfully resolved.</p>

<p>What's the proper approach to detect the path to logout.php?</p>

<p>The same question in different words:</p>

<p>How can I reliably achieve the path to the root directory (which contains my index.php) from ANY subdirectory? No matter if the html file is in /lib/subfolder or in /anotherDirectory, I want it to have a link directing to /lib/logout.php</p>

<p>On my machine it's supposed to be <a href="http://localhost/myName/folder" rel="nofollow">http://localhost/myName/folder</a> (which contains index.php and all subdirectories), on someone else's it might be <a href="http://localhost/project" rel="nofollow">http://localhost/project</a></p>

<p>How can I detect the path to application root?</p>
