How can absolute and relative paths be used effectively when including files in PHP?

When including files in PHP, using absolute paths is recommended for better reliability and portability. Absolute paths start from the root directory of the server, ensuring that the file will be included correctly regardless of the current working directory. Relative paths are based on the current working directory, which can cause issues if the script is moved or included in different locations.

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