What are the best practices for comparing user IP addresses with a list of proxy IPs in PHP?

When comparing user IP addresses with a list of proxy IPs in PHP, it is important to ensure that the comparison is done accurately to prevent unauthorized access or security breaches. One way to do this is by using the `$_SERVER['REMOTE_ADDR']` variable to retrieve the user's IP address and comparing it with a list of known proxy IPs. It is also recommended to sanitize and validate the user's IP address before performing the comparison.

$user_ip = $_SERVER['REMOTE_ADDR'];
$proxy_ips = ['192.168.1.1', '10.0.0.1']; // List of known proxy IPs

// Sanitize and validate user IP address
if(filter_var($user_ip, FILTER_VALIDATE_IP)){
    // Compare user IP with list of proxy IPs
    if(in_array($user_ip, $proxy_ips)){
        // User is using a proxy IP
        echo "Access denied. Proxy IP detected.";
    } else {
        // User is not using a proxy IP
        echo "User IP is valid.";
    }
} else {
    // Invalid user IP address
    echo "Invalid IP address.";
}