1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cookie.php
См. документацию.
1<?php
2
4
7
8class Cookie extends Http\Cookie
9{
10 public const SPREAD_SITES = 1;
11 public const SPREAD_DOMAIN = 2;
12
13 protected $spread;
14 protected $originalName;
15
23 public function __construct($name, $value, $expires = null, $addPrefix = true)
24 {
25 $this->name = ($addPrefix ? static::generateCookieName($name) : $name);
26 $this->originalName = $name;
27 $this->value = $value;
28 $this->expires = ($expires === null ? time() + 31104000 : $expires); //60*60*24*30*12
29 $this->spread = static::SPREAD_DOMAIN | static::SPREAD_SITES;
30 $this->setDefaultsFromConfig();
31 }
32
33 protected static function generateCookieName($name)
34 {
35 static $cookiePrefix = null;
36
37 if ($cookiePrefix === null)
38 {
39 $cookiePrefix = Config\Option::get("main", "cookie_name", "BITRIX_SM") . "_";
40 $cookiePrefix = static::normalizeName($cookiePrefix);
41 }
42 if (!str_starts_with($name, $cookiePrefix))
43 {
45 }
46
47 return $name;
48 }
49
50 protected function setDefaultsFromConfig()
51 {
52 $cookiesSettings = Config\Configuration::getValue('cookies');
53
54 $this->secure = ($cookiesSettings['secure'] ?? false);
55 $this->httpOnly = ($cookiesSettings['http_only'] ?? true);
56 if (isset($cookiesSettings['samesite']))
57 {
58 $this->sameSite = $cookiesSettings['samesite'];
59 }
60 }
61
62 public function getDomain(): ?string
63 {
64 if ($this->domain === null)
65 {
66 $this->domain = static::getCookieDomain();
67 }
68
69 return $this->domain;
70 }
71
72 public function getOriginalName(): string
73 {
75 }
76
77 public function setSpread($spread)
78 {
79 $this->spread = $spread;
80
81 return $this;
82 }
83
84 public function getSpread()
85 {
86 return $this->spread;
87 }
88
96 public static function getCookieDomain()
97 {
98 static $domain = null;
99
100 if ($domain !== null)
101 {
102 return $domain;
103 }
104
105 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
106 $httpHost = $request->getHttpHost();
107
108 $recordset = SiteDomainTable::getList([
109 'order' => ['DOMAIN_LENGTH' => 'ASC'],
110 'cache' => ['ttl' => 86400],
111 ]);
112
113 while ($record = $recordset->fetch())
114 {
115 if (strcasecmp(mb_substr('.' . $httpHost, -(mb_strlen($record['DOMAIN']) + 1)), "." . $record['DOMAIN']) == 0)
116 {
117 $domain = $record['DOMAIN'];
118
119 return $domain;
120 }
121 }
122
123 $domain = '';
124
125 return $domain;
126 }
127
133 public static function normalizeName(string $name): string
134 {
135 // cookie name cannot contain "=", ",", ";", " ", "\t", "\r", "\n", "\013", or "\014"
136 return preg_replace("/[=,; \\t\\r\\n\\013\\014]/", '', $name);
137 }
138}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static getValue($name)
Определения configuration.php:24
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения cookie.php:3
$cookiePrefix
Определения quickway.php:248