1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
cookie.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\Web
;
4
5
use
Bitrix\Main\Config
;
6
use
Bitrix\Main\SiteDomainTable
;
7
8
class
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
{
44
$name
=
$cookiePrefix
.
$name
;
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
{
74
return
$this->originalName
;
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
}
$request
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения
catalog_reindex.php:36
Bitrix\Main\Config\Configuration\getValue
static getValue($name)
Определения
configuration.php:24
Bitrix\Main\Config\Option\get
static get($moduleId, $name, $default="", $siteId=false)
Определения
option.php:30
Bitrix\Main\SiteDomainTable
Определения
sitedomain.php:31
Bitrix\Main\Web\Cookie
Определения
cookie.php:9
Bitrix\Main\Web\Cookie\__construct
__construct($name, $value, $expires=null, $addPrefix=true)
Определения
cookie.php:23
Bitrix\Main\Web\Cookie\getCookieDomain
static getCookieDomain()
Определения
cookie.php:96
Bitrix\Main\Web\Cookie\getOriginalName
getOriginalName()
Определения
cookie.php:72
Bitrix\Main\Web\Cookie\getDomain
getDomain()
Определения
cookie.php:62
Bitrix\Main\Web\Cookie\setDefaultsFromConfig
setDefaultsFromConfig()
Определения
cookie.php:50
Bitrix\Main\Web\Cookie\generateCookieName
static generateCookieName($name)
Определения
cookie.php:33
Bitrix\Main\Web\Cookie\SPREAD_DOMAIN
const SPREAD_DOMAIN
Определения
cookie.php:11
Bitrix\Main\Web\Cookie\setSpread
setSpread($spread)
Определения
cookie.php:77
Bitrix\Main\Web\Cookie\normalizeName
static normalizeName(string $name)
Определения
cookie.php:133
Bitrix\Main\Web\Cookie\getSpread
getSpread()
Определения
cookie.php:84
Bitrix\Main\Web\Cookie\SPREAD_SITES
const SPREAD_SITES
Определения
cookie.php:10
Bitrix\Main\Web\Cookie\$spread
$spread
Определения
cookie.php:13
Bitrix\Main\Web\Cookie\$originalName
$originalName
Определения
cookie.php:14
Bitrix\Main\Web\Http\Cookie
Определения
cookie.php:13
Bitrix\Main\Web\Http\Cookie\$value
$value
Определения
cookie.php:24
Bitrix\Main\Web\Http\Cookie\$expires
$expires
Определения
cookie.php:19
Bitrix\Main\Web\Http\Cookie\$name
$name
Определения
cookie.php:21
Bitrix\Main\Web\Http\Cookie\$domain
$domain
Определения
cookie.php:18
Bitrix\Main\Config
Определения
configuration.php:3
Bitrix\Main\Web
Определения
cookie.php:3
$cookiePrefix
$cookiePrefix
Определения
quickway.php:248
bitrix
modules
main
lib
web
cookie.php
Создано системой
1.14.0