mlocati/idna 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mlocati/idna

Composer 安装命令:

composer require mlocati/idna

包简介

Library for International Domain Names (IDNA) 2008

README 文档

README

Tests

International Domain Names PHP library

Introduction & terminology

Historically, we've been able to use domain names composed only by ASCII characters (for instance: www.example.com).

A new technique, called Internationalized Domain Names (IDN for short), allows you to use most of the Unicode characters, so that you can have for instance www.例.中国.

To grant compatibility with all the existing software that makes internet work, domain names containing non-ASCII characters are represented in Punycode, a special format that uses ASCII-only characters.

Mapping

The generation of Punycode starting from an IDN should be case insensitive: browsing to www.example.com should be the same as browsing to www.Example.COM.

In PHP, converting strings to lower case is as easy as calling strtolower, but this function does not work with characters outside the ASCII characters (in fact, it may mess up the IDN names). If you have the mbstring PHP extension, you may think to use the mb_strtolower PHP function it offers.

By the way, even mb_strtolower isn't a good choice, for these reasons:

  1. the mbstring PHP extension may not be available
  2. the mb_strtolower behaviour changes across different PHP versions (for instance, Ԩ is correctly converted to ԩ for PHP 7.0, but prior versions kept Ԩ)
  3. mb_strtolower does not translate a lot of Unicode characters that are suggested by the standards

Unicode offers a mapping table with the recommended mapping (for instance, case normalization like A to a, but also to .).

Deviation

There are two standards that define the mapping that should be applied to IDN, IDNA2003 and IDNA2008. IDNA2008 is backward compatible with IDNA2003, but there are some incompatible differences.

For instance, IDNA2003 required that ß mapped to ss, whereas IDNA2008 allows the usage of ß. So, older browsers and client softwares resolved www.schloß.com to the Punycode corresponding to www.schloss.com, whereas newer browsers resolve it to the Punycode of www.schloß.com.

Since the resulting Punycode is different (it's called deviation), this lead to big security issues, and you need to know that a domain name is deviated.

Advantages of this library

  • no dependencies from any PHP extension
  • not dependent from any other PHP library
  • consistency across different PHP versions
  • results are granted to follow the standards (it's not just a bare multibyte to punycode conversion library)
  • designed with speed in mind
  • compatible with any PHP version ranging from PHP 5.3 to the most recent PHP versions (8.2 at the time of writing this)

Sample usage

require_once 'autoload.php'; // Not required if you use composer

$domain = \MLocati\IDNA\DomainName::fromName('www。schloß.COM');

echo "Name: ", $domain->getName(), "\n";
echo "Punycode: ", $domain->getPunycode(), "\n";
echo "Deviated: ", $domain->isDeviated() ? 'yes' : 'no', "\n";
echo "Deviated Name: ", $domain->getDeviatedName(), "\n";
echo "Deviated Punycode: ", $domain->getDeviatedPunycode(), "\n";

output:

Name: www.schloß.com
Punycode: www.xn--schlo-pqa.com
Deviated: yes
Deviated Name: www.schloss.com
Deviated Punycode: www.schloss.com

Do you really want to say thank you?

You can offer me a monthly coffee or a one-time coffee 😉

mlocati/idna 适用场景与选型建议

mlocati/idna 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 976.97k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2016 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「i18n」 「idna」 「l10n」 「ascii」 「domain」 「name」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mlocati/idna 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mlocati/idna 我们能提供哪些服务?
定制开发 / 二次开发

基于 mlocati/idna 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 976.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 36
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-03