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

Commit 708390d

Browse files
committed
Bugfix
1 parent b51cc75 commit 708390d

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

analyser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function analyse_countries($mysql, $table, $field, $start = null, $end = null, $
119119
}
120120
function analyse_time($mysql, $time = null) {
121121
$timespan = null;
122-
$times = array("24h" => array("start" => "-24 HOUR", "end" => null), "7days" => array("start" => "-7 DAY", "end" => null), "30days" => "30days" => array("start" => "-30 DAY", "end" => null), "365days" => array("start" => "365 DAY", "end" => null));
122+
$times = array("24h" => array("start" => "-24 HOUR", "end" => null), "7days" => array("start" => "-7 DAY", "end" => null), "30days" => array("start" => "-30 DAY", "end" => null), "365days" => array("start" => "365 DAY", "end" => null));
123123
$start = null;
124124
$end = null;
125125
if($time != null) {

analytics.php

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class b1_analytics {
1313
public $a = array();
1414
public $s = null;
15+
public $h = null;
1516
public $d = null;
1617
public $bot_name = null;
1718
public $agent_id = null;
@@ -298,8 +299,6 @@ function getmobile() {
298299

299300
// Gets user language and country from hostname and http header
300301
function getlocation() {
301-
$this->u_ip = $this->s['REMOTE_ADDR'];
302-
$this->u_host = gethostbyaddr($this->u_ip);
303302
if(filter_var($this->u_host, FILTER_VALIDATE_IP) == false) {
304303
$domainparts = explode(".", $this->u_host);
305304
$domainend = $domainparts[count($domainparts) - 1];
@@ -311,9 +310,7 @@ function getlocation() {
311310
$this->u_country_code = $this->s["HTTP_CF_IPCOUNTRY"];
312311
}
313312
}
314-
if(isset($this->s["HTTP_ACCEPT_LANGUAGE"])) {
315-
$this->u_language = substr($this->s['HTTP_ACCEPT_LANGUAGE'], 0, 2);
316-
}
313+
$this->u_language = isset($this->s["HTTP_ACCEPT_LANGUAGE"]) ? substr($this->s['HTTP_ACCEPT_LANGUAGE'], 0, 2) : false;
317314
}
318315

319316
// Anonymizes the ip adress
@@ -330,7 +327,7 @@ function anonymize_ip() {
330327
function getisp($mysql) {
331328
$mysql->query("CREATE TABLE IF NOT EXISTS `isps` (id VARCHAR(10) PRIMARY KEY, domain VARCHAR(127) NOT NULL, name TEXT, country VARCHAR(2), last TIMESTAMP NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP);");
332329
$ispdomain = null;
333-
if(filter_var($this->u_host, FILTER_VALIDATE_IP) == false) {
330+
if(isset($this->u_host) && filter_var($this->u_host, FILTER_VALIDATE_IP) == false) {
334331
$domainparts = explode(".", $this->u_host);
335332
$ispdomain = $domainparts[count($domainparts) - 2] . "." . $domainparts[count($domainparts) - 1];
336333
}
@@ -532,13 +529,9 @@ function getubid($mysql) {
532529
// Gets information about the request and adds it to the database
533530
function getrequest($mysql) {
534531
$mysql->query("CREATE TABLE IF NOT EXISTS `requests` (id VARCHAR(15) PRIMARY KEY, accept TEXT, protocol TEXT, port INT(6), host VARCHAR(253), uri TEXT, referrer TEXT, visitor_ip VARCHAR(45) NOT NULL, visitor_country VARCHAR(2), cf_ray_id TEXT, browser_id VARCHAR(15), network_id VARCHAR(15), created TIMESTAMP DEFAULT CURRENT_TIMESTAMP);");
535-
if(isset($this->s['REQUEST_SCHEME'])) {
536-
$this->r_protocol = $this->s["REQUEST_SCHEME"];
537-
}
538-
$this->r_port = $this->s['SERVER_PORT'];
539-
if(isset($this->s["HTTP_CF_RAY"])) {
540-
$this->r_rayid = $this->s["HTTP_CF_RAY"];
541-
}
532+
$this->r_protocol = isset($this->s['REQUEST_SCHEME']) ? $this->s["REQUEST_SCHEME"] : null;
533+
$this->r_port = isset($this->s["SERVER_PORT"]) ? $this->s['SERVER_PORT'] : null;
534+
$this->r_rayid = isset($this->s["HTTP_CF_RAY"]) ? $this->s["HTTP_CF_RAY"] : null;
542535
if(isset($this->s["REQUEST_URI"])) {
543536
$uri = $this->s["REQUEST_URI"];
544537
if($uri != null && $uri != "" && $uri != "/") {
@@ -551,11 +544,9 @@ function getrequest($mysql) {
551544
$this->r_origin = $origin;
552545
}
553546
}
554-
if(isset($this->d['HTTP_ACCEPT'])) {
555-
$this->r_accept = "".explode(",", $this->s['HTTP_ACCEPT'])[0]."";
556-
}
547+
$this->r_accept = isset($this->d['HTTP_ACCEPT']) ? "".explode(",", $this->s['HTTP_ACCEPT'])[0]."" : null;
557548
$this->rid = $this->generateid(15);
558-
$this->r_domain = strtolower($this->s["HTTP_HOST"]);
549+
$this->r_domain = strtolower($this->h);
559550
$this->exgenquery($mysql, "requests", array("accept" => $this->r_accept, "protocol" => $this->r_protocol, "port" => $this->r_port, "host" => $this->r_domain, "uri" => $this->r_target, "referrer" => $this->r_origin, "visitor_ip" => $this->u_ip, "visitor_country" => $this->u_country_code, "cf_ray_id" => $this->r_rayid, "browser_id" => $this->ubid, "network_id" => $this->unid), $this->rid);
560551
}
561552

@@ -565,20 +556,25 @@ function getrequest($mysql) {
565556
function __construct($mysql, $server, $clientcookies, $anonymousips = TRUE) {
566557
if(!$mysql->connect_errno) {
567558
$this->s = $server;
568-
if(isset($server['HTTP_USER_AGENT'])) {
569-
$this->ua = strtolower($server['HTTP_USER_AGENT']);
570-
}
559+
$this->ua = isset($this->s['HTTP_USER_AGENT']) ? strtolower($this->s['HTTP_USER_AGENT']) : null;
571560
$this->c = $clientcookies;
572-
$domain = strtolower($server["HTTP_HOST"]);
573-
if(filter_var($domain, FILTER_VALIDATE_IP) == false) {
574-
$domainparts = explode(".", $domain);
575-
$this->d = $domainparts[count($domainparts) - 2] . "." . $domainparts[count($domainparts) - 1];
576-
} else { $this->d = $domain; }
577-
$this->getmobile();
578-
$this->getlocation($reader);
579-
if($anonymousips) {
561+
$this->u_ip = isset($this->s['REMOTE_ADDR']) ? $this->s['REMOTE_ADDR'] : null;
562+
if (filter_var($this->u_ip, FILTER_VALIDATE_IP)) {
563+
$this->u_host = gethostbyaddr($this->u_ip);
564+
}
565+
if($anonymousips && isset($this->s['REMOTE_ADDR'])) {
580566
$this->anonymize_ip();
581567
}
568+
if(isset($this->s["HTTP_HOST"])) {
569+
$this->h = $this->s["HTTP_HOST"];
570+
$domain = strtolower($this->h);
571+
if(filter_var($domain, FILTER_VALIDATE_IP) == false) {
572+
$domainparts = explode(".", $domain);
573+
$this->d = $domainparts[count($domainparts) - 2] . "." . $domainparts[count($domainparts) - 1];
574+
} else { $this->d = $domain; }
575+
}
576+
$this->getmobile();
577+
$this->getlocation();
582578
$this->getisp($mysql);
583579
$this->getunid($mysql);
584580
$this->getbot();
@@ -587,7 +583,7 @@ function __construct($mysql, $server, $clientcookies, $anonymousips = TRUE) {
587583
$this->getubid($mysql);
588584
$this->getrequest($mysql);
589585
} else {
590-
error_log("beranek1 analytics unable to connect to database\n");
586+
error_log("b1 web analytics unable to connect to database\n");
591587
}
592588
}
593589

0 commit comments

Comments
 (0)