What are some secure solutions for appending ?site=XXXX to a central file (index.php) in PHP?

Appending ?site=XXXX to a central file like index.php can potentially expose your application to security vulnerabilities, such as SQL injection attacks. To securely handle this parameter, you should validate and sanitize the input to prevent any malicious code execution. One way to do this is by using PHP's filter_input() function to validate and sanitize the input before using it in your application.

<?php
// Validate and sanitize the site parameter
$site = filter_input(INPUT_GET, 'site', FILTER_SANITIZE_STRING);

// Check if the site parameter is not empty
if (!empty($site)) {
    // Include the corresponding site file based on the parameter value
    include $site . '.php';
} else {
    // Handle the case when the site parameter is not provided
    echo 'Invalid site parameter';
}