定制 xoops/regdom 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

xoops/regdom

最新稳定版本:v2.1.0-beta1

Composer 安装命令:

composer require 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.

README 文档

README

alt XOOPS CMS

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 8.2 or later
  • ext-mbstring required
  • ext-intl recommended (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/.

统计信息

  • 总下载量: 6.76k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: (Apache-2.0 OR MPL-2.0) 4b6313e34e5a110d62ea45bc2fa234da29af6f70
  • 更新时间: 2024-07-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固