IIS servers doesn’t always set the PHP standard variable, $_SERVER[‘DOCUMENT_ROOT’]

How do you set that in one place, your configuration file that you include in all your php programs, so the rest of your code has the document root set like on Apache servers?

Output $_SERVER to see what IS given that you might be able to use:

echo "
"; print_r($_SERVER); echo "

"; print_r($_ENV); echo "


In this example, the SCRIPT_FILENAME and SCRIPT_NAME are set.

Modify the code below to use what is given to get DOCUMENT_ROOT:

if (!isset($_SERVER['DOCUMENT_ROOT']) || $_SERVER['DOCUMENT_ROOT'] === '') {

Now you can use $_SERVER[‘DOCUMENT_ROOT’] normally:

$docroot = getenv("DOCUMENT_ROOT"); 
include_once "$docroot/folder/yourfile.php";