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