private static function Database::ipBetween in Smart IP 7.2
Same name and namespace in other branches
- 6.2 includes/vendor/ip2location/ip2location-php/IP2Location.php \IP2Location\Database::ipBetween()
Determine whether the given IP number of the given version lies between the given bounds
This function will return 0 if the given ip number falls within the given bounds for the given version, -1 if it falls below, and 1 if it falls above.
@access private @static
Parameters
int $version IP version to use (either 4 or 6):
int|string $ip IP number to check (int for IPv4, string for IPv6):
int|string $low Lower bound (int for IPv4, string for IPv6):
int|string $high Uppoer bound (int for IPv4, string for IPv6):
Return value
int
1 call to Database::ipBetween()
- Database::binSearch in includes/
vendor/ ip2location/ ip2location-php/ IP2Location.php - Perform a binary search on the given IP number and return a pointer to its record
File
- includes/
vendor/ ip2location/ ip2location-php/ IP2Location.php, line 945
Class
- Database
- IP2Location database class
Namespace
IP2LocationCode
private static function ipBetween($version, $ip, $low, $high) {
if (4 === $version) {
// Use normal PHP ints
if ($low <= $ip) {
if ($ip < $high) {
return 0;
}
else {
return 1;
}
}
else {
return -1;
}
}
else {
// Use BCMath
if (bccomp($low, $ip, 0) <= 0) {
if (bccomp($ip, $high, 0) <= -1) {
return 0;
}
else {
return 1;
}
}
else {
return -1;
}
}
}