PHPackages                             yannkuesthardt/laravel-spamprotect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. yannkuesthardt/laravel-spamprotect

ActiveLibrary[Security](/categories/security)

yannkuesthardt/laravel-spamprotect
==================================

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

2.0.2(11mo ago)28772MITPHPPHP &gt;=8.1CI passing

Since Oct 15Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/yannkuesthardt/Laravel-SpamProtect)[ Packagist](https://packagist.org/packages/yannkuesthardt/laravel-spamprotect)[ RSS](/packages/yannkuesthardt-laravel-spamprotect/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (5)Versions (10)Used By (0)

Laravel SpamProtect
===================

[](#laravel-spamprotect)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bd42ef082243f9c5f0c93e76bbed5f58a404e59d31e0f717197ed08d4dd1f1c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79616e6e6b7565737468617264742f6c61726176656c2d7370616d70726f746563743f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yannkuesthardt/laravel-spamprotect)[![Total Downloads](https://camo.githubusercontent.com/21a67b132507907a6ec13e54a12bdce3b0fef8e12f4f4496bbff434cae4bc662/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79616e6e6b7565737468617264742f6c61726176656c2d7370616d70726f746563743f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yannkuesthardt/laravel-spamprotect)[![License](https://camo.githubusercontent.com/cfabffcd3acb49fd5b53cdb21c0db0c6157c0783c3e6178080196aeb3bdf94b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f79616e6e6b7565737468617264742f6c61726176656c2d7370616d70726f746563743f7374796c653d666c61742d737175617265)](https://github.com/yannkuesthardt/Laravel-SpamProtect/blob/main/LICENSE.md)[![GitHub Build Status](https://camo.githubusercontent.com/7f003e7c28779db5decf00d48b79e5d3aaa07d6587b8bd78bbe2d7601051a1dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f79616e6e6b7565737468617264742f4c61726176656c2d5370616d50726f746563742f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/yannkuesthardt/Laravel-SpamProtect)

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.

```

    hello@example.com

```

***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](#installation)
- [Upgrade](#upgrade)
- [Usage](#usage)
- [Customization](#customization)
- [Testing](#testing)
- [Changelog](#changelog)
- [Security Vulnerabilities](#security-vulnerabilities)
- [License](#license)

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- PHP 8.1 or higher
- [Laravel](https://github.com/laravel/framework) 10.0 or higher

### Getting Started

[](#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)

### Upgrade from v1 to v2

[](#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](https://www.npmjs.com/package/crypto-js) and require it in your own JavaScript first. As CryptoJS has been discontinued and most browsers offer native support with tools such as [Crypto](https://developer.mozilla.org/en-US/docs/Web/API/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
-----

[](#usage)

### E-Mail Address

[](#e-mail-address)

To encrypt an email address use the following blade component:

```

```

This will result in the following HTML code:

```

    hello@example.com

```

### Phone Number

[](#phone-number)

To encrypt a phone number use the following blade component:

```

```

This will result in the following HTML code:

```

    +1 234 567890

```

### Custom Text

[](#custom-text)

You can also use a custom text for the link:

```

    My Cutom Text

```

This will result in the following HTML code:

```

    My Custom Text

```

### Attributes

[](#attributes)

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

```
