Object oriented PHP library for querying Mozilla's Public Suffix List to determine the registrable domain portion of URLs and validate cookie domains per RFC 6265. Adapted from Florian Sager's regdom library.
For more information on public suffixes, see publicsuffix.org.
- PHP 7.4 or later
ext-intlrecommended (for internationalized domain name support)
composer require xoops/regdomuse Xoops\RegDom\RegisteredDomain;
$regdom = new RegisteredDomain();
echo $regdom->getRegisteredDomain('https://www.google.com/');
// Output: google.com
echo $regdom->getRegisteredDomain('theregister.co.uk');
// Output: theregister.co.uk
var_dump($regdom->getRegisteredDomain('co.uk'));
// Output: NULL (co.uk is a public suffix, not a registrable domain)
// IDN support (requires ext-intl)
echo $regdom->getRegisteredDomain('www.münchen.de');
// Output: münchen.deuse Xoops\RegDom\RegisteredDomain;
// Validates if a cookie domain is appropriate for a given host
RegisteredDomain::domainMatches('www.example.com', 'example.com'); // true
RegisteredDomain::domainMatches('example.com', 'com'); // false (public suffix)
RegisteredDomain::domainMatches('google.com', 'facebook.com'); // false (cross-domain)
RegisteredDomain::domainMatches('192.168.1.1', '192.168.1.1'); // false (IP addresses)use Xoops\RegDom\PublicSuffixList;
$psl = new PublicSuffixList();
$psl->isPublicSuffix('com'); // true
$psl->isPublicSuffix('co.uk'); // true
$psl->isPublicSuffix('example.com'); // false
$psl->getPublicSuffix('www.example.co.uk'); // 'co.uk'
$psl->isException('www.ck'); // true (PSL exception rule)$metadata = $psl->getMetadata();
// Returns: active_cache, last_updated, days_old, rule_counts, needs_updatecomposer run update-pslSet the XOOPS_SKIP_PSL_UPDATE environment variable to skip automatic PSL
updates during composer install/update (useful in CI or restricted networks).
When defined and set to false, disables PSL-based validation in
RegisteredDomain::domainMatches(). Defaults to true when undefined.
Environment variable. When set (to any value), prevents automatic PSL download during Composer post-install/update hooks.
composer install # Install dependencies
composer ci # Run all checks: lint + analyse + test
composer test # Run PHPUnit tests
composer lint # Check code style (PSR-12)
composer analyse # Run PHPStan (level max)
composer fix # Auto-fix code style issuesReg-dom was written by Florian Sager, 2009-02-05, sager@agitos.de
Marcus Bointon's adapted code: https://github.com/Synchro/regdom-php
The PHP library code in this repository is licensed under the Apache License 2.0. See LICENSE.txt for the full Apache 2.0 license text.
The bundled Public Suffix List data/cache is derived from Mozilla's Public Suffix List and is available under the Mozilla Public License 2.0 (MPL-2.0). For details, see https://www.mozilla.org/en-US/MPL/2.0/ and https://publicsuffix.org/.
