/usr/share/php/Nette/Http/Helpers.php is in php-nette 2.4-20160731-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | <?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
namespace Nette\Http;
use Nette;
use Nette\Utils\DateTime;
/**
* Rendering helpers for HTTP.
*/
class Helpers
{
use Nette\StaticClass;
/**
* Returns HTTP valid date format.
* @param string|int|\DateTimeInterface
* @return string
*/
public static function formatDate($time)
{
$time = DateTime::from($time);
$time->setTimezone(new \DateTimeZone('GMT'));
return $time->format('D, d M Y H:i:s \G\M\T');
}
/**
* Is IP address in CIDR block?
* @return bool
*/
public static function ipMatch($ip, $mask)
{
list($mask, $size) = explode('/', $mask . '/');
$tmp = function ($n) { return sprintf('%032b', $n); };
$ip = implode('', array_map($tmp, unpack('N*', inet_pton($ip))));
$mask = implode('', array_map($tmp, unpack('N*', inet_pton($mask))));
$max = strlen($ip);
if (!$max || $max !== strlen($mask) || (int) $size < 0 || (int) $size > $max) {
return FALSE;
}
return strncmp($ip, $mask, $size === '' ? $max : (int) $size) === 0;
}
/**
* Removes duplicate cookies from response.
* @return void
* @internal
*/
public static function removeDuplicateCookies()
{
if (headers_sent($file, $line) || ini_get('suhosin.cookie.encrypt')) {
return;
}
$flatten = [];
foreach (headers_list() as $header) {
if (preg_match('#^Set-Cookie: .+?=#', $header, $m)) {
$flatten[$m[0]] = $header;
header_remove('Set-Cookie');
}
}
foreach (array_values($flatten) as $key => $header) {
header($header, $key === 0);
}
}
}
|