What are the potential security risks of displaying directory contents on a website using PHP?

Displaying directory contents on a website using PHP can potentially expose sensitive information such as file paths, file names, and file types to malicious users. This can lead to security risks such as unauthorized access, information disclosure, and potential exploitation of vulnerabilities. To mitigate this risk, it is important to ensure that directory listing is disabled and to implement proper access control measures to restrict access to sensitive directories.

// Disable directory listing in PHP
if (is_dir($directory)) {
    header("HTTP/1.1 403 Forbidden");
    die("Directory listing is not allowed.");
}