- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/web/cookie.php
- Класс: BitrixMainWebCookie
- Вызов: Cookie::getCookieDomain
static function getCookieDomain()
{
static $domain = null;
if ($domain !== null)
{
return $domain;
}
$request = BitrixMainContext::getCurrent()->getRequest();
$httpHost = $request->getHttpHost();
$cacheFlags = ConfigConfiguration::getValue('cache_flags');
$cacheTtl = ($cacheFlags['site_domain'] ?? 0);
if ($cacheTtl === false)
{
$connection = BitrixMainApplication::getConnection();
$sqlHelper = $connection->getSqlHelper();
$sql = "SELECT DOMAIN ".
"FROM b_lang_domain ".
"WHERE '".$sqlHelper->forSql('.'.$httpHost)."' like ".$sqlHelper->getConcatFunction("'%.'", "DOMAIN")." ".
"ORDER BY ".$sqlHelper->getLengthFunction("DOMAIN")." ";
$recordset = $connection->query($sql);
if ($record = $recordset->fetch())
{
$domain = $record['DOMAIN'];
}
}
else
{
$managedCache = BitrixMainApplication::getInstance()->getManagedCache();
if ($managedCache->read($cacheTtl, 'b_lang_domain', 'b_lang_domain'))
{
$arLangDomain = $managedCache->get('b_lang_domain');
}
else
{
$arLangDomain = ['DOMAIN' => [], 'LID' => []];
$connection = BitrixMainApplication::getConnection();
$sqlHelper = $connection->getSqlHelper();
$recordset = $connection->query(
"SELECT * ".
"FROM b_lang_domain ".
"ORDER BY ".$sqlHelper->getLengthFunction("DOMAIN")
);
while ($record = $recordset->fetch())
{
//it's a bit tricky, the cache is used somewhere else, that's why we have the LID key here.
$arLangDomain['DOMAIN'][] = $record;
$arLangDomain['LID'][$record['LID']][] = $record;
}
$managedCache->set('b_lang_domain', $arLangDomain);
}
foreach ($arLangDomain['DOMAIN'] as $record)
{
if (strcasecmp(mb_substr('.'.$httpHost, -(mb_strlen($record['DOMAIN']) + 1)), ".".$record['DOMAIN']) == 0)
{
$domain = $record['DOMAIN'];
break;
}
}
}
if ($domain === null)
{
$domain = '';
}
return $domain;
}