Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationLatte
      • ApplicationTracy
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsLatte
      • Framework
      • HttpTracy
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy

Classes

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

Interfaces

  • IRequest
  • IResponse
  • ISessionStorage
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://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:         $ipv4 = strpos($ip, '.');
29:         $max = $ipv4 ? 32 : 128;
30:         if (($ipv4 xor strpos($mask, '.')) || $size < 0 || $size > $max) {
31:             return FALSE;
32:         } elseif ($ipv4) {
33:             $arr = array(ip2long($ip), ip2long($mask));
34:         } else {
35:             $arr = unpack('N*', inet_pton($ip) . inet_pton($mask));
36:             $size = $size === '' ? 0 : $max - $size;
37:         }
38:         $bits = implode('', array_map(function ($n) {
39:                 return sprintf('%032b', $n);
40:         }, $arr));
41:         return substr($bits, 0, $max - $size) === substr($bits, $max, $max - $size);
42:     }
43: 
44: }
45: 
Nette 2.2.2 API API documentation generated by ApiGen 2.8.0