PHP code example of vinou / bot-counter

1. Go to this page and download the library: Download vinou/bot-counter 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/ */

    

vinou / bot-counter example snippets


use Vinou\BotCounter\BotCounter;

$counter = new BotCounter(__DIR__ . '/var/logs/bots.json');
$counter->count('Googlebot');

use Vinou\BotCounter\BotCounter;
use Vinou\BotCounter\CrawlerDetectAdapter;

$bots = new CrawlerDetectAdapter(new BotCounter(__DIR__ . '/var/logs/bots.json'));
$bots->record();   // counts only if the request came from a crawler

$data = $counter->read();

echo $data['total'];                          // all visits ever counted
echo $data['bots']['googlebot']['last7days']; // rolling window

$counter = new BotCounter($file, [
    'windows'     => [1, 7, 30],  // produces last1days, last7days, last30days
    'maxEntries'  => 500,         // beyond this, everything lands under 'other'
    'overflowKey' => 'other',
]);