HDTuto.com

How to detect web crawler in Laravel ?


In this article, i will let you know about hot to detect we crawler from bot user agents i your laravel 5 application. this tutorial will help you to implement web scraping in laravel 5 app. we will use jaybizzle/laravel-crawler-detect composer package for detect crawler.

So just follow bellow two things for detect we crawler. here first we will install package and another thing i will give you example, how to use from route.

Install Laravel Crawler Detect Package:

here, we will install Laravel Crawler Detect composer package for detect crawler in laravel 5 application. So let's run bellow command in your laravel app.

composer require jaybizzle/laravel-crawler-detect

After that you have to add into providers array of configuration file. So let's add following way:

config/app.php

<?php

return [

....

'providers' => [

....

Jaybizzle\LaravelCrawlerDetect\LaravelCrawlerDetectServiceProvider::class,

],

'aliases' => [

....

'Crawler' => 'Jaybizzle\LaravelCrawlerDetect\Facades\LaravelCrawlerDetect',

],

...

Use:

Here is i gave you simple example with route for detect Crawler in laravel 5.5 application.

routes/web.php

Route::get('/detect-crawler', function(){

if(Crawler::isCrawler()) {

dd("true if crawler user agent detected");

}

dd("Without crawler detecter.");

});

i hope you found best solution....






December 26, 2017 | Category : PHP Laravel
Related Posts