Files
medicalalert-web-reloaded/wp/wp-content/plugins/ip-geo-block/includes/Net/IPv4.php
Tony Volpe be83910651 Merged in feature/280-dev-dev01 (pull request #21)
auto-patch  280-dev-dev01-2024-01-19T16_41_58

* auto-patch  280-dev-dev01-2024-01-19T16_41_58
2024-01-19 16:44:43 +00:00

16 lines
448 B
PHP

<?php
/**
* Class to provide IPv4 calculations
*
* PHP versions 4, 5 and 7
*
* @link https://stackoverflow.com/questions/594112/matching-an-ip-to-a-cidr-mask-in-php-5#answer-594134
*/
class Net_IPv4 {
public static function ipInNetwork( $ip, $cidr ) {
list( $subnet, $bitmask ) = explode( '/', $cidr );
$bitmask = -1 << ( 32 - $bitmask );
return ( ip2long( $ip ) & $bitmask ) === ( ip2long( $subnet ) & $bitmask );
}
}