How to detect the path to the application root?
Question by auge
I’m trying to dynamically detect the root directory of my page in order to direct to a specific script.
echo ($_SERVER['DOCUMENT_ROOT']);
It prints /myName/folder/index.php
I’d like to use in a html-file to enter a certain script like this:
<a href="<?php $_SERVER['DOCUMENT_ROOT'].'lib/logout.php'?>">log out</a>
This seems to be in bad syntax, the path is not successfully resolved.
What’s the proper approach to detect the path to logout.php?
The same question in different words:
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
On my machine it’s supposed to be http://localhost/myName/folder (which contains index.php and all subdirectories), on someone else’s it might be http://localhost/project
How can I detect the path to application root?