Are there any security risks to consider when loading PHP pages within PHP pages?

When loading PHP pages within PHP pages, there is a security risk known as Remote File Inclusion (RFI) where an attacker can potentially execute malicious code on the server. To mitigate this risk, it is important to validate and sanitize any user input used to include files, and avoid using user input directly in include or require statements.

// Example of including a PHP page securely
$allowed_pages = ['page1.php', 'page2.php', 'page3.php'];
$page = $_GET['page'];

if (in_array($page, $allowed_pages)) {
    include($page);
} else {
    echo "Invalid page requested.";
}