https://github.com/nicolasbeauvais/laravel-botscout
Block malicious scripts using botscout.com protection for your laravel app
https://github.com/nicolasbeauvais/laravel-botscout
bot botscout laravel laravel-package php protection
Last synced: 5 months ago
JSON representation
Block malicious scripts using botscout.com protection for your laravel app
- Host: GitHub
- URL: https://github.com/nicolasbeauvais/laravel-botscout
- Owner: nicolasbeauvais
- License: mit
- Archived: true
- Created: 2017-02-12T17:53:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-06-07T13:07:38.000Z (almost 7 years ago)
- Last Synced: 2025-11-21T03:03:33.035Z (6 months ago)
- Topics: bot, botscout, laravel, laravel-package, php, protection
- Language: PHP
- Homepage:
- Size: 18.6 KB
- Stars: 63
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-laravel - Botscout protection - Block malicious scripts using botscout.com protection for your laravel app. \[03/03/2017\] (Packages / Authentication/Security)
README
# Laravel BotScout
[](https://packagist.org/packages/nicolasbeauvais/laravel-botscout)
[](https://travis-ci.org/nicolasbeauvais/laravel-botscout)
[](https://insight.sensiolabs.com/projects/005620f8-d154-41f1-bc9b-4c27a1cf36ab)
[](https://scrutinizer-ci.com/g/nicolasbeauvais/laravel-botscout)
[](https://packagist.org/packages/nicolasbeauvais/laravel-botscout)

Protect your website against automated scripts using the [botscout.com](http://botscout.com/) API.
## Installation
You can install the package via composer:
``` bash
composer require nicolasbeauvais/laravel-botscout
```
Next, you must install the service provider:
```php
// config/app.php
'providers' => [
...
NicolasBeauvais\LaravelBotScout\BotScoutServiceProvider::class,
];
```
Add your [botscout.com](http://botscout.com/getkey.htm) api key to the `.env` file:
```bash
BOTSCOUT_SECRET=your-api-key
```
If needed you can also publish the config file:
```bash
php artisan vendor:publish --provider="NicolasBeauvais\LaravelBotScout\BotScoutServiceProvider" --tag="config"
```
If you want to make use of the facade you must install it as well:
```php
// config/app.php
'aliases' => [
...
'BotScout' => NicolasBeauvais\LaravelBotScout\BotScoutFacade::class,
];
```
## Usage
You are highly advised to read the [BotScout.com API guide](http://botscout.com/api.htm) to understand the meaning of
each method.
### Validator
You can easily use botscout in your existing validators:
``` php
// Validate name
$validator = Validator::make(['name' => 'John Doe'], [
'name' => 'required|botscout_name'
]);
// Validate email
$validator = Validator::make(['email' => 'toto@gmail.com'], [
'email' => 'required|botscout_mail'
]);
// Validate ip
$validator = Validator::make(['ip' => '127.0.0.1'], [
'ip' => 'required|botscout_ip'
]);
```
Note that you will need to create the validation message by yourself, as described in the [Laravel documentation](https://laravel.com/docs/5.5/validation#custom-error-messages).
### Facade
You can use the BotScout facade anywhere in your app:
```php
BotScout::multi('John Doe', 'email@test.com', '127.0.0.1')->isValid();
BotScout::all('John Doe')->isValid();
BotScout::name('John Doe')->isValid();
BotScout::mail('email@test.com')->isValid();
BotScout::ip('127.0.0.1')->isValid();
// We also include a quick way of testing a user with integrated exception catch
BotScout::check('John Doe', 'email@test.com', '127.0.0.1'); // true or false
```
### Real life example using the check method
The `check` method is the recommended way to validate a register form:
>The `check` method is a wrapper to the `multi`method that catch any http error / timeout. If the botscout api is not responding, the method will return false.
```php
// Create a classic validation
$validator = Validator::make($request->all(), [
'email' => 'required|email|unique:users',
'name' => 'required|max:20',
]);
$validator->after(function ($validator) {
if (!BotScout::check($request->get('name'), $request->get('email'), $request->ip())) {
$validator->errors()->add('email', 'Sorry, it looks like your a bot!');
}
});
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Testing
``` bash
$ composer test
```
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security
If you discover any security related issues, please email nicolasbeauvais1@gmail.com instead of using the issue tracker.
## Credits
- [Nicolas Beauvais](https://github.com/nicolasbeauvais)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.