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
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

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

Interfaces

  • IRequest
  • IResponse
  • ISessionStorage
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
 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:     use Nette\StaticClass;
20: 
21:     /**
22:      * Returns HTTP valid date format.
23:      * @param  string|int|\DateTimeInterface
24:      * @return string
25:      */
26:     public static function formatDate($time)
27:     {
28:         $time = DateTime::from($time);
29:         $time->setTimezone(new \DateTimeZone('GMT'));
30:         return $time->format('D, d M Y H:i:s \G\M\T');
31:     }
32: 
33: 
34:     /**
35:      * Is IP address in CIDR block?
36:      * @return bool
37:      */
38:     public static function ipMatch($ip, $mask)
39:     {
40:         list($mask, $size) = explode('/', $mask . '/');
41:         $tmp = function ($n) { return sprintf('%032b', $n); };
42:         $ip = implode('', array_map($tmp, unpack('N*', inet_pton($ip))));
43:         $mask = implode('', array_map($tmp, unpack('N*', inet_pton($mask))));
44:         $max = strlen($ip);
45:         if (!$max || $max !== strlen($mask) || (int) $size < 0 || (int) $size > $max) {
46:             return false;
47:         }
48:         return strncmp($ip, $mask, $size === '' ? $max : (int) $size) === 0;
49:     }
50: 
51: 
52:     /**
53:      * Removes duplicate cookies from response.
54:      * @return void
55:      * @internal
56:      */
57:     public static function removeDuplicateCookies()
58:     {
59:         if (headers_sent($file, $line) || ini_get('suhosin.cookie.encrypt')) {
60:             return;
61:         }
62: 
63:         $flatten = [];
64:         foreach (headers_list() as $header) {
65:             if (preg_match('#^Set-Cookie: .+?=#', $header, $m)) {
66:                 $flatten[$m[0]] = $header;
67:                 header_remove('Set-Cookie');
68:             }
69:         }
70:         foreach (array_values($flatten) as $key => $header) {
71:             header($header, $key === 0);
72:         }
73:     }
74: }
75: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0