diff --git a/webanalytics.php b/webanalytics.php index 299520b..55676b3 100644 --- a/webanalytics.php +++ b/webanalytics.php @@ -41,11 +41,11 @@ class web_db_manager { private $connection = null; // Database user credentials - private $user = null; - private $password = null; + private $user; + private $password; // Database information - private $dsn = null; + private $dsn; // Convert the given array to a SQL filter function get_filter($filter) { @@ -500,7 +500,7 @@ function identify_browser() { } if($row == null) $row = $this->db_manager->first("wa_trackers", "id,browser_id", ["fingerprint" => $this->get_fingerprint(), "domain" => $this->d]); if($row != null) { - $this->db_manager->update("wa_trackers", ["time" => date('Y-m-d H:i:s')], ["id" => $this->c["webid"]]); + $this->db_manager->update("wa_trackers", ["time" => date('Y-m-d H:i:s')], ["id" => $row["id"]]); if($this->db_manager->first("wa_browsers", "id", ["id" => $row["browser_id"]]) != null) { setcookie("webid", $row["id"], time()+60*60*24*180, "/", $this->d); $this->db_manager->update("wa_browsers", [ @@ -591,7 +591,11 @@ function __construct(web_db_manager $db_manager, $server, $cookies, $anonymize_i $this->a_language = isset($this->s["HTTP_ACCEPT_LANGUAGE"]) ? $this->s['HTTP_ACCEPT_LANGUAGE'] : null; $this->u_language = isset($this->s["HTTP_ACCEPT_LANGUAGE"]) ? substr($this->s['HTTP_ACCEPT_LANGUAGE'], 0, 2) : null; $this->check_database(); - $this->u_ip = $this->save_ip($this->s['REMOTE_ADDR'], $anonymize_ip); + if(isset($this->s["HTTP_X_FORWARDED_FOR"])) { + $this->u_ip = $this->save_ip($this->s['HTTP_X_FORWARDED_FOR'], $anonymize_ip); + } else { + $this->u_ip = $this->save_ip($this->s['REMOTE_ADDR'], $anonymize_ip); + } $this->profile_id = $this->get_profile(); $this->ubid = $this->identify_browser(); $this->session_id = $this->get_session($this->ubid); diff --git a/webstatistics.php b/webstatistics.php index 2da068e..ce352fc 100644 --- a/webstatistics.php +++ b/webstatistics.php @@ -49,9 +49,11 @@ function array_key_last($array) { $top_countries[$country[0]] = $country[1]; $continent = $country_to_continent[strtoupper($country[0])]; if(!array_key_exists($continent, $top_continents)) { + $top_continents[$continent] = $country[1]; $total_continents = $total_continents + 1; + } else { + $top_continents[$continent] = $top_continents[$continent] + $country[1]; } - $top_continents[$continent] = $top_continents[$continent] + $country[1]; } else { $top_countries["?"] = $country[1]; $top_continents["?"] = $country[1]; @@ -62,17 +64,25 @@ function array_key_last($array) { arsort($top_continents); $total_countries = 0; $top_countriesvo = array(); +$top_continentsvo = array(); foreach($web_analytics_db->query("SELECT `country`, COUNT(*) FROM wa_browsers GROUP BY `country` ORDER BY COUNT(*) DESC;") as $country) { if($country[0] != "" && $country[0] != null) { $top_countriesvo[$country[0]] = $country[1]; + $continent = $country_to_continent[strtoupper($country[0])]; + if(!array_key_exists($continent, $top_continentsvo)) { + $top_continentsvo[$continent] = $country[1]; + } else { + $top_continentsvo[$continent] = $top_continentsvo[$continent] + $country[1]; + } $total_countries = $total_countries + 1; } else { $top_countriesvo["?"] = $country[1]; } } +$top_originsvo = array_merge($top_countriesvo, $top_continentsvo); $top_languages = array(); $total_languages = 0; -foreach($tplngsr = $web_analytics_db->query("SELECT `language`, COUNT(*) FROM wa_browsers GROUP BY `language` ORDER BY COUNT(*) DESC;") as $language) { +foreach($web_analytics_db->query("SELECT `language`, COUNT(*) FROM wa_browsers GROUP BY `language` ORDER BY COUNT(*) DESC;") as $language) { if($language[0] != "" && $language[0] != null) { $top_languages[$language[0]] = $language[1]; $total_languages = $total_languages + 1; @@ -404,10 +414,10 @@ function drawobyrChart() { $i = 0; foreach ($top_origins as $key => $value) { if($i == 0) { - echo "['".$key."', ".$value.", ".$top_countriesvo[$key]."]"; + echo "['".$key."', ".$value.", ".$top_originsvo[$key]."]"; $i++; } else { - echo ",['".$key."', ".$value.", ".$top_countriesvo[$key]."]"; + echo ",['".$key."', ".$value.", ".$top_originsvo[$key]."]"; } } ?>