An open API service indexing awesome lists of open source software.

https://github.com/beastbytes/email-obfuscator

Yii3 widget to obfuscate email addresses to prevent harvesting by bots
https://github.com/beastbytes/email-obfuscator

Last synced: 2 months ago
JSON representation

Yii3 widget to obfuscate email addresses to prevent harvesting by bots

Awesome Lists containing this project

README

        

# emailobfuscator
Widget to obfuscate an email address to help prevent harvesting by spam bots.

If JavaScript is disabled on the client, the widget will output either a message or an obfuscated version of the email address.

If JavaScript is enabled the
output is replaced with (by default) a mailto link showing (again by default) the email address. The content of the
mailto link can be customised.

For license information see the [LICENSE](LICENSE.md) file.

## Installation

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist beastbytes/emailobfuscator
```

or add

```json
"beastbytes/emailobfuscator": "^1.0"
```

to the require section of your composer.json.

## Usage

Use this extension in a view.

To output the default message ("This e-mail address is protected to prevent harvesting by spam-bots")

```php
echo EmailObfuscator::widget([
'email' => '[email protected]'
]);
```

### Output

#### JavaScript Disabled

```html
This e-mail address is protected to prevent harvesting by spam-bots
```

#### JavaScript Enabled

```html
[email protected]
```

---

To output a different message set content['obfuscated']
```php
echo EmailObfuscator::widget([
'email' => '[email protected]',
'content' => ['obfuscated' => 'Enable JavaScript to see the email address']
]);
```

### Output

#### JavaScript Disabled

```html
Enable JavaScript to see the email address
```

#### JavaScript Enabled

```html
[email protected]
```

---

To output an obfuscated version of the email address set the obfuscators: "my dot address at example dot com"

```php
echo EmailObfuscator::widget([
'email' => '[email protected]',
'obfuscators' => [' dot ', ' at ']
]);
```

### Output

#### JavaScript Disabled

```html
my dot address at example dot com
```

#### JavaScript Enabled

```html
[email protected]
```

---

To set the content of the mailto link, set content['clear']

```php
echo EmailObfuscator::widget([
'email' => '[email protected]',
'content' => ['clear' => 'by email']
]);
```

### Output

#### JavaScript Disabled

```html
This e-mail address is protected to prevent harvesting by spam-bots
```

#### JavaScript Enabled

```html
by email
```