misc.php 468 B

1234567891011121314151617181920
  1. <?php
  2. function get_data(?bool $is_associative = false): array {
  3. $existing_json_data = file_get_contents('data.json');
  4. $data = json_decode($existing_json_data, $is_associative);
  5. return $data;
  6. }
  7. function ip_in_range($ip, $range) {
  8. list($subnet, $bits) = explode('/', $range);
  9. $ip_decimal = ip2long($ip);
  10. $subnet_decimal = ip2long($subnet);
  11. $mask = -1 << (32 - $bits);
  12. return ($ip_decimal & $mask) === ($subnet_decimal & $mask);
  13. }
  14. ?>