mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-16 17:46:59 +02:00
Update helpers.php
This commit is contained in:
parent
91f5b7d824
commit
c9982bbcc0
1 changed files with 16 additions and 0 deletions
|
@ -1099,4 +1099,20 @@ function validateTcnId(string $domain, string $noticeId, string $notAfterUtc): b
|
||||||
|
|
||||||
// Compare
|
// Compare
|
||||||
return hash_equals($tcnChecksum, $crc32Hex);
|
return hash_equals($tcnChecksum, $crc32Hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractDomainFromHost(string $hostname, array $tlds): ?string {
|
||||||
|
$hostname = strtolower($hostname);
|
||||||
|
foreach ($tlds as $tld) {
|
||||||
|
$tld = ltrim(strtolower($tld), '.'); // remove dot if present
|
||||||
|
if (str_ends_with($hostname, '.' . $tld)) {
|
||||||
|
$labels = explode('.', $hostname);
|
||||||
|
$tld_parts = explode('.', $tld);
|
||||||
|
$domain_parts = array_slice($labels, -count($tld_parts) - 1); // 1 label before TLD
|
||||||
|
if (count($domain_parts) === count($tld_parts) + 1) {
|
||||||
|
return implode('.', $domain_parts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue