Files
preland/components/site-domain.php
2026-10-21 17:24:14 +03:00

12 lines
600 B
PHP

<?php
/** Домен преленда не связан с config.host основного сайта/API. */
function prelandSiteDomain(array $server): string
{
foreach ([$server['HTTP_HOST'] ?? '', $server['SERVER_NAME'] ?? ''] as $candidate) {
if (!is_string($candidate) || preg_match('/[\s\/@?#<>]/', $candidate)) continue;
$host = strtolower(rtrim(preg_replace('/:\d+$/', '', $candidate), '.'));
if (strlen($host) <= 253 && preg_match('/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/D', $host)) return $host;
}
return '';
}