PHP code example of jaybizzle / laravel-crawler-detect

1. Go to this page and download the library: Download jaybizzle/laravel-crawler-detect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jaybizzle / laravel-crawler-detect example snippets


use Crawler;

// Check the current visitor's user agent
if (Crawler::isCrawler()) {
    // true if a crawler user agent was detected
}

// Or pass a user agent string to check
if (Crawler::isCrawler('Mozilla/5.0 (compatible; aiHitBot/2.9; +https://www.aihitdata.com/about)')) {
    // true if a crawler user agent was detected
}

// Output the name of the bot that matched (if any)
echo Crawler::getMatches();

use Jaybizzle\CrawlerDetect\CrawlerDetect;

public function index(CrawlerDetect $crawlerDetect)
{
    if ($crawlerDetect->isCrawler()) {
        // ...
    }
}

use Illuminate\Http\Request;

public function index(Request $request)
{
    if ($request->isCrawler()) {
        // Output the name of the bot that matched (if any)
        echo $request->crawler()->getMatches();
    }

    // Or pass a user agent string to check
    if ($request->isCrawler('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')) {
        // ...
    }
}