Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Diagnostics
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
      • Diagnostics
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • PhpGenerator
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
  • NetteModule
  • none

Classes

  • Context
  • FileUpload
  • Helpers
  • Request
  • RequestFactory
  • Response
  • Session
  • SessionSection
  • Url
  • UrlScript
  • UserStorage

Interfaces

  • IRequest
  • IResponse
  • ISessionStorage
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\Http;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Rendering helpers for HTTP.
15:  *
16:  * @author     David Grudl
17:  */
18: class Helpers
19: {
20: 
21:     /**
22:      * Is IP address in CIDR block?
23:      * @return bool
24:      */
25:     public static function ipMatch($ip, $mask)
26:     {
27:         list($mask, $size) = explode('/', $mask . '/');
28:         $tmp = function ($n) { return sprintf('%032b', $n); };
29:         $ip = implode('', array_map($tmp, unpack('N*', inet_pton($ip))));
30:         $mask = implode('', array_map($tmp, unpack('N*', inet_pton($mask))));
31:         $max = strlen($ip);
32:         if (!$max || $max !== strlen($mask) || $size < 0 || $size > $max) {
33:             return FALSE;
34:         }
35:         return strncmp($ip, $mask, $size === '' ? $max : $size) === 0;
36:     }
37: 
38: }
39: 
Nette 2.1 API documentation generated by ApiGen 2.8.0