Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • 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
    • Bridges
      • Nette

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:     Nette\Utils\DateTime;
12: 
13: 
14: /**
15:  * Rendering helpers for HTTP.
16:  *
17:  * @author     David Grudl
18:  */
19: class Helpers
20: {
21: 
22:     /**
23:      * Returns HTTP valid date format.
24:      * @param  string|int|\DateTime
25:      * @return string
26:      */
27:     public static function formatDate($time)
28:     {
29:         $time = DateTime::from($time);
30:         $time->setTimezone(new \DateTimeZone('GMT'));
31:         return $time->format('D, d M Y H:i:s \G\M\T');
32:     }
33: 
34: 
35:     /**
36:      * Is IP address in CIDR block?
37:      * @return bool
38:      */
39:     public static function ipMatch($ip, $mask)
40:     {
41:         list($mask, $size) = explode('/', $mask . '/');
42:         $ipv4 = strpos($ip, '.');
43:         $max = $ipv4 ? 32 : 128;
44:         if (($ipv4 xor strpos($mask, '.')) || $size < 0 || $size > $max) {
45:             return FALSE;
46:         } elseif ($ipv4) {
47:             $arr = array(ip2long($ip), ip2long($mask));
48:         } else {
49:             $arr = unpack('N*', inet_pton($ip) . inet_pton($mask));
50:             $size = $size === '' ? 0 : $max - $size;
51:         }
52:         $bits = implode('', array_map(function ($n) {
53:             return sprintf('%032b', $n);
54:         }, $arr));
55:         return substr($bits, 0, $max - $size) === substr($bits, $max, $max - $size);
56:     }
57: 
58: 
59:     /**
60:      * Removes duplicate cookies from response.
61:      * @return void
62:      * @internal
63:      */
64:     public static function removeDuplicateCookies()
65:     {
66:         if (headers_sent($file, $line) || ini_get('suhosin.cookie.encrypt')) {
67:             return;
68:         }
69: 
70:         $flatten = array();
71:         foreach (headers_list() as $header) {
72:             if (preg_match('#^Set-Cookie: .+?=#', $header, $m)) {
73:                 $flatten[$m[0]] = $header;
74:                 header_remove('Set-Cookie');
75:             }
76:         }
77:         foreach (array_values($flatten) as $key => $header) {
78:             header($header, $key === 0);
79:         }
80:     }
81: 
82: 
83:     /**
84:      * @internal
85:      */
86:     public static function stripSlashes($arr, $onlyKeys = FALSE)
87:     {
88:         $res = array();
89:         foreach ($arr as $k => $v) {
90:             $res[stripslashes($k)] = is_array($v)
91:                 ? self::stripSlashes($v, $onlyKeys)
92:                 : ($onlyKeys ? $v : stripslashes($v));
93:         }
94:         return $res;
95:     }
96: 
97: }
98: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0