What are common pitfalls when using the $_SERVER['DOCUMENT_ROOT'] variable in PHP includes?

When using $_SERVER['DOCUMENT_ROOT'] in PHP includes, a common pitfall is that the value may not always be set or accurate, leading to potential issues with file paths. To solve this, it's recommended to define a constant in your configuration file that stores the document root path and use that constant in your includes instead.

// Define a constant for the document root path
define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);

// Now use the constant in your includes
include(DOCUMENT_ROOT . '/path/to/file.php');