You are here

public function IPRangesManager::ipIsBanned in IP Ranges 8

File

lib/Drupal/ip_ranges/IPRangesManager.php, line 13

Class

IPRangesManager

Namespace

Drupal\ip_ranges

Code

public function ipIsBanned($ip) {
  $args = array(
    ':ip' => ip2long($ip),
  );
  $sql = "SELECT * FROM {ip_ranges} WHERE type = :type AND ip_lower <= :ip AND ip_higher >= :ip";
  $banned = $this->connection
    ->queryRange($sql, 0, 1, $args + array(
    ':type' => 0,
  ))
    ->fetchField() && !$this->connection
    ->queryRange($sql, 0, 1, $args + array(
    ':type' => 1,
  ))
    ->fetchField();
  return $banned;
}