PHP code example of esi / simple_counter

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

    

esi / simple_counter example snippets




// Load the composer autoload file, if not already loaded
atfileStorage;
use Esi\SimpleCounter\Configuration\FlatfileConfiguration;

/**
 * $options is an array of:
 *
 * array{
 *     logDir: string,
 *     countFile: string,
 *     ipFile: string,
 *     imageDir: string,
 *     imageExt: string,
 *     uniqueOnly: bool,
 *     asImage: bool,
 *     honorDnt: bool,
 *     visitorTextString?: string
 * }
 *
 * Default values are:
 *
 * [
 *      'logDir'            => dirname(__DIR__, 2) . '/counter/logs/',
 *      'countFile'         => 'counter.json',
 *      'ipFile'            => 'ips.json',
 *      'imageDir'          => dirname(__DIR__, 2) . '/counter/images/',
 *      'imageExt'          => '.png',
 *      'uniqueOnly'        => true,
 *      'asImage'           => false,
 *      'honorDnt'          => false,
 *      'visitorTextString' => 'You are visitor #%s',
 * ] 
 */
// Valid options are:
$options = [
    'logDir'            => '/path/to/some/dir/logs',
    'countFile'         => 'counter.json',
    'ipFile'            => 'ips.json',
    'imageDir'          => '/path/to/some/dir/images',
    'imageExt'          => '.png', // '.png', '.jpg' etc. default images are PNG images
    'asImage'           => true,   // true = images, false = plain text
    'uniqueOnly'        => true,   // true = counts only unique ip's, false = counts all,
    'honorDnt'          => false,
    'visitorTextString' => 'You are visitor #%s',
];

/**
 * Important note regarding the 'visitorTextString'. This is the text that is shown if 'asImage' is false.
 *
 * For example, by default, it would show: You are visitor #123.
 * If you wanted to change it to something like: Counter: #123,
 * you would set the 'visitorTextString' option to:
 * 
 * 'Counter: #%s'
 */

/**
 * When creating the counter instance, a Storage implementation with a valid Configuration is