HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/AppData/Roaming/Code/User/History/655c119a/QtHS.php
<?php
date_default_timezone_set('Asia/Taipei');
$logFile = 'visitor_log.csv';

$ipSummary = [];

if (file_exists($logFile)) {
    if (($handle = fopen($logFile, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            // CSV Structure: [0]Time, [1]ScriptName, [2]IP, [3]Area
            $script = $data[1];
            $ip = $data[2];
            $area = $data[3];

            // Create a unique key for each Script + IP combination
            $key = $script . '___' . $ip;

            if (!isset($ipSummary[$key])) {
                $ipSummary[$key] = [
                    'script' => $script,
                    'ip'     => $ip,
                    'area'   => $area,
                    'count'  => 0
                ];
            }
            $ipSummary[$key]['count']++;
        }
        fclose($handle);
    }
}

// Sort the list so the highest number of hits appears at the top
uasort($ipSummary, function($a, $b) {
    return $b['count'] <=> $a['count'];
});
?>