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;
    }
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;
    }
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 ; }
Checks if two IP addresses are the same or if the first is the anonymized
version of the other.

@param string $ip
@param string $currentIp This IP should not be anonymized.
@return bool
Checks if two IP addresses are the same or if the first is the anonymized version of the other .