Skip to content
PHP Logo

What is the issue with $_SERVER['DOCUMENT_ROOT'] on Windows systems in PHP?

The issue with $_SERVER['DOCUMENT_ROOT'] on Windows systems in PHP is that it may return the incorrect path due to differences in the way Windows handles file paths compared to Unix-based systems. To solve this issue, you can use the dirname() function to get the parent directory of the current script and construct the correct document root path.

php
$document_root = str_replace('\\', '/', dirname(__FILE__));