How can absolute paths in PHP scripts lead to errors and what is the recommended approach?

Using absolute paths in PHP scripts can lead to errors when the script is moved to a different server or directory, as the absolute path may no longer be valid. To avoid this issue, it is recommended to use relative paths instead, which are not dependent on the server or directory structure.

// Incorrect absolute path
include('/var/www/html/includes/config.php');

// Recommended relative path
include('includes/config.php');