xoops / regdom
A robust domain parser for PHP, using the Mozilla Public Suffix List to determine the registrable domain and validate cookie domains per RFC 6265.
Fund package maintenance!
XOOPS
Opencollective
xoops.org/modules/donations
Installs: 2 498
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 3
Open Issues: 0
pkg:composer/xoops/regdom
Requires
- php: ^7.4 || ^8.0
- symfony/polyfill-mbstring: ^1.33
- symfony/polyfill-php80: ^1.33
Requires (Dev)
- phpstan/phpstan: ^1.10 || ^2.0
- phpunit/phpunit: ^9.6 || ^10.0 || ^11.0
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.11
Suggests
- ext-intl: Required for internationalized domain name (IDN) support
This package is auto-updated.
Last update: 2026-02-08 18:32:00 UTC
README
RegDom - Registered Domain Check in PHP
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.
Requirements
- PHP 7.4 or later
ext-intlrecommended (for internationalized domain name support)
Installation
composer require xoops/regdom
Usage
Extracting the Registered Domain
use 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.de
Cookie Domain Validation (RFC 6265)
use 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)
Querying the Public Suffix List
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)
Checking PSL Cache Status
$metadata = $psl->getMetadata(); // Returns: active_cache, last_updated, days_old, rule_counts, needs_update
Updating the Public Suffix List
composer run update-psl
Set the XOOPS_SKIP_PSL_UPDATE environment variable to skip automatic PSL
updates during composer install/update (useful in CI or restricted networks).
Configuration
XOOPS_COOKIE_DOMAIN_USE_PSL
When defined and set to false, disables PSL-based validation in
RegisteredDomain::domainMatches(). Defaults to true when undefined.
XOOPS_SKIP_PSL_UPDATE
Environment variable. When set (to any value), prevents automatic PSL download during Composer post-install/update hooks.
Development
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 issues
Credits
Reg-dom was written by Florian Sager, 2009-02-05, sager@agitos.de
Marcus Bointon's adapted code: https://github.com/Synchro/regdom-php
License
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/.