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

Commit

Permalink
Fix statistics page and cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
beranek1 committed Sep 13, 2020
1 parent 77f4825 commit 9a0f69e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
14 changes: 9 additions & 5 deletions webanalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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", [
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 14 additions & 4 deletions webstatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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]."]";
}
}
?>
Expand Down

0 comments on commit 9a0f69e

Please sign in to comment.