Is using $_SERVER["DOCUMENT_ROOT"] a reliable method for obtaining the root directory in PHP?

Using $_SERVER["DOCUMENT_ROOT"] can be a reliable method for obtaining the root directory in PHP, as it returns the document root directory under which the current script is executing. However, it's important to be aware that the value of $_SERVER["DOCUMENT_ROOT"] can vary depending on the server configuration. It's always a good practice to validate and sanitize this value before using it in your code to prevent any security vulnerabilities.

$rootDirectory = $_SERVER["DOCUMENT_ROOT"];
// Validate and sanitize $rootDirectory before using it in your code