How can file_exists function be leveraged to enhance the security of including subpages in a PHP system?

When including subpages in a PHP system, it is important to ensure that the files being included actually exist to prevent potential security vulnerabilities such as including malicious files. The file_exists function can be leveraged to check if the file exists before including it, thus enhancing the security of the system.

$page = $_GET['page'];

if (file_exists($page . '.php')) {
    include($page . '.php');
} else {
    echo 'Page not found';
}