From 746ac1ea3f0fbf470da3f1728f6852915a41a44e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 5 Mar 2018 15:45:22 +0100 Subject: [PATCH] Prevent confusion between arrays Signed-off-by: DL6ER --- api_db.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api_db.php b/api_db.php index b4bd8cb3..7c126297 100644 --- a/api_db.php +++ b/api_db.php @@ -131,7 +131,7 @@ if (isset($_GET['topClients']) && $auth) $stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER); $results = $stmt->execute(); - $clients = array(); + $clientnums = array(); if(!is_bool($results)) while ($row = $results->fetchArray()) @@ -139,25 +139,25 @@ if (isset($_GET['topClients']) && $auth) $c = resolveOnlyHostname($row[0]); - if(array_key_exists($c, $clients)) + if(array_key_exists($c, $clientnums)) { // Entry already exists, add to it (might appear multiple times due to mixed capitalization in the database) - $clients[$c] += intval($row[1]); + $clientnums[$c] += intval($row[1]); } else { // Entry does not yet exist - $clients[$c] = intval($row[1]); + $clientnums[$c] = intval($row[1]); } } // Sort by number of hits - arsort($clients); + arsort($clientnums); // Extract only the first ten entries - $clients = array_slice($clients, 0, 10); + $clientnums = array_slice($clientnums, 0, 10); - $result = array('top_sources' => $clients); + $result = array('top_sources' => $clientnums); $data = array_merge($data, $result); }