Piwik\Plugins\UserCountry\LocationProvider\GeoIp\ServerBased::isSameOrAnonymizedIp PHP Method

isSameOrAnonymizedIp() public static method

Checks if two IP addresses are the same or if the first is the anonymized version of the other.
public static isSameOrAnonymizedIp ( string $ip, string $currentIp ) : boolean
$ip string
$currentIp string This IP should not be anonymized.
return boolean
    public static function isSameOrAnonymizedIp($ip, $currentIp)
    {
        $ip = array_reverse(explode('.', $ip));
        $currentIp = array_reverse(explode('.', $currentIp));
        if (count($ip) != count($currentIp)) {
            return false;
        }
        foreach ($ip as $i => $byte) {
            if ($byte == 0) {
                $currentIp[$i] = 0;
            } else {
                break;
            }
        }
        foreach ($ip as $i => $byte) {
            if ($byte != $currentIp[$i]) {
                return false;
            }
        }
        return true;
    }