I’ve been working on an exciting project, and one of the first task was to integrate Google Safe Browsing into the project. The Safe Browsing APIs (v4) let you check URLs against Google’s constantly updated lists of unsafe web resources. However, I couldn’t find a working package for Laravel 5.4 so I decided to create my own and share it on github and packagist.
Installation
Run the following from the Terminal:
1 |
composer require dominykasgel/google-safe-browsing |
Next, add your new provider to the providers array of config/app.php:
1 2 3 |
'providers' => [ dominykasgel\GoogleSafeBrowsing\GoogleSafeBrowsingServiceProvider::class, ] |
Finally, add aliases to the aliases array of config/app.php:
1 |
'aliases' => [ 'GoogleSafeBrowsing' => dominykasgel\GoogleSafeBrowsing\Facades\GoogleSafeBrowsingFacade::class ] |
Preparation
You need to get your API key from Google Safe Browsing API.
Publish the config file.
1 |
php artisan vendor:publish --force |
Set your API key in YOUR-APP/config/google_safe_browsing.php
1 |
'api_key' => '*************************************' |
Usage
1 2 3 4 5 |
GoogleSafeBrowsing::lookup( 'https://www.github.com' ); if ( GoogleSafeBrowsing::isSecure() ) { echo 'Secure!'; } |
More examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
GoogleSafeBrowsing::lookup( 'https://www.github.com' ); if ( GoogleSafeBrowsing::isSecure() ) { echo 'Secure!'; } if ( GoogleSafeBrowsing::isSocialEngineering() ) { echo 'Social Engineering!'; } if ( GoogleSafeBrowsing::isMalware() ) { echo 'Malware!'; } if ( GoogleSafeBrowsing::isUnwanted() ) { echo 'Unwatend software!'; } if ( GoogleSafeBrowsing::isHarmfulApplication() ) { echo 'Harmful application!'; } |
License
The package is licensed under the GPL v3 License.