kiwa/link-obfuscator 问题修复 & 功能扩展

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

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

kiwa/link-obfuscator

Composer 安装命令:

composer require kiwa/link-obfuscator

包简介

Strong link obfuscation with PHP and JavaScript. Object-oriented, using the Rot47 algorithm. Hides https, email, phone and sms links from being crawled by spambots.

README 文档

README

PHP from Packagist Latest Stable Version Total Downloads License

Kiwa Logo

Kiwa Link Obfuscator

Strong link obfuscation with PHP and JavaScript. Object-oriented, using the Rot47 algorithm. Hides https, email, phone and sms links from being crawled by spambots.

Installation

This library is made for the use with Composer. Add it to your project by running $ composer require kiwa/link-obfuscator.

Usage

There are four classes available: Https, Mail, Phone and SMS. All of them can be used in the same way:

<?php

use Kiwa\LinkObfuscator\Mail;

echo new Mail('hello@bitandblack.com');

// Basically equal to <a href="mailto:hello@bitandblack.com">hello@bitandblack.com</a>

The output will be: <a data-href="%3E2%3A%3DE%40i96%3D%3D%40o3%3AE2%3F53%3D24%3C%5D4%40%3E" data-id="_klo0">|||96%3D%3D%40o3%3AE2%3F53%3D24%3C%5D4%40%3E</a>, followed by some JavaScript code.

There are some parameters available:

  1. The first one is the link href
  2. Second one is the link description
  3. The third can be every additional parts like class names
  4. If the link description should also be encrypted.

Using them, the example above would look like:

<?php

use Kiwa\LinkObfuscator\Mail;

echo new Mail('hello@bitandblack.com', 'Mail us', ['class' => 'btn'], false);

// Basically equal to <a href="mailto:hello@bitandblack.com" class="btn">Mail us</a>

Now the output is: <a data-href="%3E2%3A%3DE%40i96%3D%3D%40o3%3AE2%3F53%3D24%3C%5D4%40%3E" data-id="_klo0" class="btn">Mail us</a>, also followed by some JavaScript code.

The JavaScript will then decrypt the link. But instead of appending raw data into the page, the link href will be stored in some event listeners. So even if the page will be parsed with active JavaScript, the link will simply look like <a href="javascript:void(0);">hello<span>@</span>bitandblack.com</a>.

Options

Encryption

The Kiwa Link Obfuscator uses the Rot47 algorithm per default. You can change this by adding a custom algorithm using AbstractLink::setEncryption(new MyCustomEncryption()). Please note that the algorithm needs also to be available in JavaScript.

UID

The default prefix for all link ids is _klo. This id is stored as data-id to keep the id free for your usage. To change the prefix you can call AbstractLink::setUidPrefix('myCustomPrefix').

JavaScript

Every HTML link will have its own JavaScript code at the end. The first of them has also the functions which are needed to create functional links. If you have a lot of links in one page, want to keep your page DRY, or whatever else, you can disable this functionality and use the code in your own way.

There are three parts of JavaScript code, which can be disabled:

<?php

use Kiwa\LinkObfuscator\AbstractLink;

AbstractLink::disableAddingActionJS();
AbstractLink::disableAddingBasicJS();
AbstractLink::disableAddingEncryptionJS();

Now you can add that code to your JavaScript file, for example by writing

import { handleLink } from "/vendor/kiwa/link-obfuscator/src/Basic";
import { encrypt } from "/vendor/kiwa/link-obfuscator/src/Encryption/Rot47";
global.encrypt = encrypt;

Now a custom code is needed as replacement for the Action.js. This could be:

const links = document.querySelectorAll("a[data-id^='_klo']");

links.forEach((link) => handleLink(link));

Help

If you have any questions, feel free to contact us under hello@bitandblack.com.

Further information about Bit&Black can be found under www.bitandblack.com.

kiwa/link-obfuscator 适用场景与选型建议

kiwa/link-obfuscator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 kiwa/link-obfuscator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 7.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-23