PHP code example of sajjadef98 / visitors

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

    

sajjadef98 / visitors example snippets




use Visitors\Visitors;

$config = [
    'host'     => 'localhost',
    'username' => 'root',
    'password' => '',
    'db'       => 'your_database',
    'port'     => 3306,
    'prefix'   => '',
    'charset'  => 'utf8mb4',
    'errmode'  => 'exception'
];

$url = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$visitors = new Visitors(new MysqliDb($config), $url);

$tracker = new Visitors\Insert_User_Data(new MysqliDb($config));
$tracker->GUDI(); // ذخیره خودکار اطلاعات بازدید

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $visitors->chartApi(); // خروجی JSON برای AJAX
    die();
}

if (isset($_GET)) {
    $visitors->chart(); // نمایش صفحه با نمودار
    die();
}



use Visitors\Visitors;

$config = [
    'host'     => 'localhost',
    'username' => 'root',
    'password' => '',
    'db'       => 'your_database',
    'port'     => 3306,
    'prefix'   => '',
    'charset'  => 'utf8mb4',
    'errmode'  => 'exception'
];

$url = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$visitors = new Visitors(new MysqliDb($config), $url);

$tracker = new Visitors\Insert_User_Data(new MysqliDb($config));
$tracker->GUDI(); // Auto-save visit data

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $visitors->chartApi(); // JSON output for AJAX
    die();
}

if (isset($_GET)) {
    $visitors->chart(); // Display chart page
    die();
}