How can the use of relative path vs. $_SERVER['DOCUMENT_ROOT'] affect file access in PHP scripts?

Using relative paths can cause issues with file access in PHP scripts because they are based on the current working directory of the script, which can change depending on where the script is being executed from. On the other hand, using $_SERVER['DOCUMENT_ROOT'] provides the absolute path to the document root of the server, ensuring consistent file access regardless of the script's location.

// Using $_SERVER['DOCUMENT_ROOT'] to include a file
include $_SERVER['DOCUMENT_ROOT'] . '/path/to/file.php';