IP2Location.php
public function get_cidr($ip) {
    // extract IP version and number
    list($ipVersion, $ipNumber) = self::ipVersionAndNumber($ip);
    // perform the binary search proper (if the IP address was invalid, binSearch will return false)
    $resp = $this->binSearch($ipVersion, $ipNumber, true);
    if(!empty($resp)) {
      list($ip_from, $ip_to) = $resp;
      $i=32; $mask=1;
      while(($ip_to & $mask) == 0) {
        $mask *= 2; $i--;
      }
      $ip = long2ip($ip_from);
      return "$ip/$i";
    }
    return false;
  }
public function get_cidr($ip) {
    // extract IP version and number
    list($ipVersion, $ipNumber) = self::ipVersionAndNumber($ip);
    // perform the binary search proper (if the IP address was invalid, binSearch will return false)
    $resp = $this->binSearch($ipVersion, $ipNumber, true);
    if(!empty($resp)) {
      list($ip_from, $ip_to) = $resp;
      $i=32; $mask=1;
      while(($ip_to & $mask) == 0) {
        $mask *= 2; $i--;
      }
      $ip = long2ip($ip_from);
      return "$ip/$i";
    }
    return false;
  }
public function get_cidr ( $ ip ) { // extract IP version and number list ( $ ipVersion , $ ipNumber ) = self :: ipVersionAndNumber ( $ ip ) ; // perform the binary search proper (if the IP address was invalid, binSearch will return false) $ resp = $ this -> binSearch ( $ ipVersion , $ ipNumber , true ) ; if ( ! empty ( $ resp ) ) { list ( $ ip_from , $ ip_to ) = $ resp ; $ i = 32 ; $ mask = 1 ; while ( ( $ ip_to & $ mask ) == 0 ) { $ mask *= 2 ; $ i -- ; } $ ip = long2ip ( $ ip_from ) ; return "$ip/$i" ; } return false ; }
For a given IP address, returns the cidr of his sub-network.

For example, calling get_cidr('91.200.12.233') returns '91.200.0.0/13'.
Useful to setup "Deny From 91.200.0.0/13" in .htaccess file for Apache2
server against spam.
For a given IP address returns the cidr of his sub - network .