What are some common pitfalls to avoid when implementing toggleable includes in PHP for a website?

One common pitfall to avoid when implementing toggleable includes in PHP for a website is using user-input directly in the include statement, which can lead to security vulnerabilities like remote code execution. To prevent this, always sanitize and validate user input before using it in includes.

// Example of properly sanitizing user input before using it in includes
$user_input = $_GET['page'];
$allowed_pages = ['page1', 'page2', 'page3'];

if (in_array($user_input, $allowed_pages)) {
    include($user_input . '.php');
} else {
    include('error.php');
}