How can the use of absolute paths in PHP scripts enhance security and prevent vulnerabilities?

Using absolute paths in PHP scripts can enhance security by preventing path traversal attacks. By specifying the exact path to files and directories on the server, it ensures that only intended files are accessed and prevents malicious users from accessing sensitive system files. This practice also helps in preventing vulnerabilities such as directory traversal attacks, where attackers manipulate file paths to access unauthorized files.

// Incorrect usage of relative path
include('config.php');

// Correct usage of absolute path
include('/var/www/html/config.php');