Another small fix in domain check

This commit is contained in:
Pinga 2025-02-07 18:38:12 +02:00
parent fc604786cf
commit 8ca5d5a53d
2 changed files with 22 additions and 7 deletions

View file

@ -360,9 +360,18 @@ function extractDomainAndTLD($urlString) {
} }
// Use the PHP Domain Parser library for real TLDs // Use the PHP Domain Parser library for real TLDs
$tlds = TopLevelDomains::fromString($fileContent); try {
$domain = Domain::fromIDNA2008($host); // Use the PHP Domain Parser library for real TLDs
$resolvedTLD = $tlds->resolve($domain)->suffix()->toString(); $tlds = TopLevelDomains::fromString($fileContent);
$domain = Domain::fromIDNA2008($host);
$resolvedTLD = $tlds->resolve($domain)->suffix()->toString();
} catch (\Pdp\Exception $e) { // Catch domain parser exceptions
$_SESSION['slimFlash']['error'][] = 'Domain parsing error: ' . $e->getMessage();
return ['error' => 'Domain parsing error: ' . $e->getMessage()];
} catch (\Exception $e) { // Catch any other unexpected exceptions
$_SESSION['slimFlash']['error'][] = 'Unexpected error: ' . $e->getMessage();
return ['error' => 'Unexpected error: ' . $e->getMessage()];
}
// Handle cases with multi-level TLDs // Handle cases with multi-level TLDs
$possibleTLDs = []; $possibleTLDs = [];

View file

@ -300,10 +300,16 @@ function extractDomainAndTLD($urlString) {
return $result; return $result;
} }
// Use the PHP Domain Parser library for real TLDs try {
$tlds = TopLevelDomains::fromString($fileContent); // Use the PHP Domain Parser library for real TLDs
$domain = Domain::fromIDNA2008($host); $tlds = TopLevelDomains::fromString($fileContent);
$resolvedTLD = $tlds->resolve($domain)->suffix()->toString(); $domain = Domain::fromIDNA2008($host);
$resolvedTLD = $tlds->resolve($domain)->suffix()->toString();
} catch (\Pdp\Exception $e) { // Catch domain parser exceptions
throw new \Exception('Domain parsing error: ' . $e->getMessage());
} catch (\Exception $e) { // Catch any other unexpected exceptions
throw new \Exception('Unexpected error: ' . $e->getMessage());
}
// Handle cases with multi-level TLDs // Handle cases with multi-level TLDs
$possibleTLDs = []; $possibleTLDs = [];