$_SERVER[‘DOCUMENT_ROOT’] allows one to provide an absolute path to a file.
However, if the file is under the document root, is there an equivalent to $_SERVER[‘DOCUMENT_ROOT’]?
For example, I want to link to config.php in /home/user/config/ from files in the public_html directory. What is the best, most portable way to do this?
If PHP can require/include the file, a hacker could do file_get_contents() on the file with a script they managed to upload into the document root.
I generally keep people out of files I don’t want them potentially execute directly by doing a ‘if (!defined(“SOME_CONSTANT”)) exit();’ at the top of the file and then make sure that it gets define()'d before including the file. Not every host offers space outside of the document root, which could make migration to another server difficult.