定制 yannkuesthardt/laravel-spamprotect 二次开发

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

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

yannkuesthardt/laravel-spamprotect

Composer 安装命令:

composer require yannkuesthardt/laravel-spamprotect

包简介

Encrypt e-mail addresses and phone numbers to protect against unwanted crawlers & spam.

README 文档

README

Latest Version on Packagist Total Downloads License GitHub Build Status

Laravel SpamProtect is a simple package, that encrypts email addresses and phone numbers to protect them against unwanted crawlers and spam.

It encrypts the target of your link and uses JS to decrypt it on the client side. This way, the email address is not visible in the HTML source code and can't be crawled by bots reading hrefs.

Additionally, some common chars used in e-mail addresses and phone numbers are replaced with HTML entities to make it even harder for bots to crawl.

<a href="#" data-spamprotect-token="eyJjdCI6Ijky...">
    hello@example.com
</a>

Security Note: Do not use this extension to pass sensitive data to the frontend. The encryption is only meant to stop crawlers and can easily be circumvented by a human.

Installation

Requirements

  • PHP 8.2 or higher
  • Laravel 12.0 or higher

Getting Started

You can install the package via composer:

composer require yannkuesthardt/laravel-spamprotect

Run the installation command to generate a new encryption key and clear necessary caches.

php artisan spamprotect:install

Add the following two blade directives somewhere in your HTML body tag.

@spamprotectKey
@spamprotectJs

Hint: Optionally you can override the default path to the JavaScript file: @spamprotectJs('your/custom/path/to/spamprotect/spamprotect.js')

Upgrade

Upgrade from v1 to v2

A few things have changed since version 1, so please read this carefully to avoid any issues.

If you used v1 in the past, you needed to publish our JavaScript to be accessible via @spamprotectJs. We have now added routing to the package, so you can just use @spamprotectJs without publishing our JavaScript first. If you have set a custom path via the blade directive or the config, remove it to get the default JavaScript via route. You may have to republish the config file, depending on your setup.

Additionally, in v1 you needed to install CryptoJS and require it in your own JavaScript first. As CryptoJS has been discontinued and most browsers offer native support with tools such as Crypto, we have rebuilt this extension to work with native JavaScript. For our new JavaScript to work either use @spamprotectJs without any custom path to access the new routing to our default JavaScript or republish the JavaScript file yourself. If not used anywhere else in your project feel free to completely remove CryptoJS.

Usage

E-Mail Address

To encrypt an email address use the following blade component:

<x-encrypt-email email="hello@example.com"/>

This will result in the following HTML code:

<a href="#" data-spamprotect-token="aVN2anJHTHJL...">
    hello@example.com
</a>

Phone Number

To encrypt a phone number use the following blade component:

<x-encrypt-phone phone="+1234567890"/>

This will result in the following HTML code:

<a href="#" data-spamprotect-token="xaVBiZU9rbUR...">
    +1 234 567890
</a>

Custom Text

You can also use a custom text for the link:

<x-encrypt-email email="hello@example.com">
    My Cutom Text
</x-encrypt-email>

This will result in the following HTML code:

<a href="#" data-spamprotect-token="eyJjdCI6Ilk4...">
    My Custom Text
</a>

Attributes

You can add HTML attributes (e.g. class, id, etc.) to the generated code by passing them to the components.

<x-encrypt-email class="my-class" id="my-id" ...

This will result in the following HTML code:

<a class="my-class" id="my-id" ...

Customization

You can generate a new encryption key using:

php artisan spamprotect:key

You can publish the config using:

php artisan vendor:publish --tag="laravel-spamprotect-config"

In the config you can customize the URL used for the default JavaScript or override the path completely.

You can publish the assets (javascript) using:

php artisan vendor:publish --tag="laravel-spamprotect-assets"

You can publish the views using

php artisan vendor:publish --tag="laravel-spamprotect-views"

Contributing

Feel free to suggest changes, ask for new features or fix bugs yourself. We're sure there are a lot of improvements that could be made, and we would be very happy to merge useful pull requests. Thanks!

Testing

PHPUnit

composer test

PHPStan

composer phpstan

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.

yannkuesthardt/laravel-spamprotect 适用场景与选型建议

yannkuesthardt/laravel-spamprotect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.04k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 yannkuesthardt/laravel-spamprotect 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-15