Skip to content
This repository was archived by the owner on Apr 9, 2023. It is now read-only.

Commit 9a0f69e

Browse files
committed
Fix statistics page and cookies
1 parent 77f4825 commit 9a0f69e

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

webanalytics.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class web_db_manager {
4141
private $connection = null;
4242

4343
// Database user credentials
44-
private $user = null;
45-
private $password = null;
44+
private $user;
45+
private $password;
4646

4747
// Database information
48-
private $dsn = null;
48+
private $dsn;
4949

5050
// Convert the given array to a SQL filter
5151
function get_filter($filter) {
@@ -500,7 +500,7 @@ function identify_browser() {
500500
}
501501
if($row == null) $row = $this->db_manager->first("wa_trackers", "id,browser_id", ["fingerprint" => $this->get_fingerprint(), "domain" => $this->d]);
502502
if($row != null) {
503-
$this->db_manager->update("wa_trackers", ["time" => date('Y-m-d H:i:s')], ["id" => $this->c["webid"]]);
503+
$this->db_manager->update("wa_trackers", ["time" => date('Y-m-d H:i:s')], ["id" => $row["id"]]);
504504
if($this->db_manager->first("wa_browsers", "id", ["id" => $row["browser_id"]]) != null) {
505505
setcookie("webid", $row["id"], time()+60*60*24*180, "/", $this->d);
506506
$this->db_manager->update("wa_browsers", [
@@ -591,7 +591,11 @@ function __construct(web_db_manager $db_manager, $server, $cookies, $anonymize_i
591591
$this->a_language = isset($this->s["HTTP_ACCEPT_LANGUAGE"]) ? $this->s['HTTP_ACCEPT_LANGUAGE'] : null;
592592
$this->u_language = isset($this->s["HTTP_ACCEPT_LANGUAGE"]) ? substr($this->s['HTTP_ACCEPT_LANGUAGE'], 0, 2) : null;
593593
$this->check_database();
594-
$this->u_ip = $this->save_ip($this->s['REMOTE_ADDR'], $anonymize_ip);
594+
if(isset($this->s["HTTP_X_FORWARDED_FOR"])) {
595+
$this->u_ip = $this->save_ip($this->s['HTTP_X_FORWARDED_FOR'], $anonymize_ip);
596+
} else {
597+
$this->u_ip = $this->save_ip($this->s['REMOTE_ADDR'], $anonymize_ip);
598+
}
595599
$this->profile_id = $this->get_profile();
596600
$this->ubid = $this->identify_browser();
597601
$this->session_id = $this->get_session($this->ubid);

webstatistics.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ function array_key_last($array) {
4949
$top_countries[$country[0]] = $country[1];
5050
$continent = $country_to_continent[strtoupper($country[0])];
5151
if(!array_key_exists($continent, $top_continents)) {
52+
$top_continents[$continent] = $country[1];
5253
$total_continents = $total_continents + 1;
54+
} else {
55+
$top_continents[$continent] = $top_continents[$continent] + $country[1];
5356
}
54-
$top_continents[$continent] = $top_continents[$continent] + $country[1];
5557
} else {
5658
$top_countries["?"] = $country[1];
5759
$top_continents["?"] = $country[1];
@@ -62,17 +64,25 @@ function array_key_last($array) {
6264
arsort($top_continents);
6365
$total_countries = 0;
6466
$top_countriesvo = array();
67+
$top_continentsvo = array();
6568
foreach($web_analytics_db->query("SELECT `country`, COUNT(*) FROM wa_browsers GROUP BY `country` ORDER BY COUNT(*) DESC;") as $country) {
6669
if($country[0] != "" && $country[0] != null) {
6770
$top_countriesvo[$country[0]] = $country[1];
71+
$continent = $country_to_continent[strtoupper($country[0])];
72+
if(!array_key_exists($continent, $top_continentsvo)) {
73+
$top_continentsvo[$continent] = $country[1];
74+
} else {
75+
$top_continentsvo[$continent] = $top_continentsvo[$continent] + $country[1];
76+
}
6877
$total_countries = $total_countries + 1;
6978
} else {
7079
$top_countriesvo["?"] = $country[1];
7180
}
7281
}
82+
$top_originsvo = array_merge($top_countriesvo, $top_continentsvo);
7383
$top_languages = array();
7484
$total_languages = 0;
75-
foreach($tplngsr = $web_analytics_db->query("SELECT `language`, COUNT(*) FROM wa_browsers GROUP BY `language` ORDER BY COUNT(*) DESC;") as $language) {
85+
foreach($web_analytics_db->query("SELECT `language`, COUNT(*) FROM wa_browsers GROUP BY `language` ORDER BY COUNT(*) DESC;") as $language) {
7686
if($language[0] != "" && $language[0] != null) {
7787
$top_languages[$language[0]] = $language[1];
7888
$total_languages = $total_languages + 1;
@@ -404,10 +414,10 @@ function drawobyrChart() {
404414
$i = 0;
405415
foreach ($top_origins as $key => $value) {
406416
if($i == 0) {
407-
echo "['".$key."', ".$value.", ".$top_countriesvo[$key]."]";
417+
echo "['".$key."', ".$value.", ".$top_originsvo[$key]."]";
408418
$i++;
409419
} else {
410-
echo ",['".$key."', ".$value.", ".$top_countriesvo[$key]."]";
420+
echo ",['".$key."', ".$value.", ".$top_originsvo[$key]."]";
411421
}
412422
}
413423
?>

0 commit comments

Comments
 (0)