Skip to content

Commit ee6a383

Browse files
authored
Add files via upload
1 parent b778009 commit ee6a383

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

access.class.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* [CHANGELOG]
77
* 2021-03-08 -> Class created
8-
* 2021-03-11 -> Added getIP() method
8+
* 2021-03-19 -> Improved return methods for unknows user agents - this can help to improve the info arrays
99
*/
1010

1111
class Access
@@ -86,56 +86,45 @@ public function __construct()
8686
$this->access['robot'] = $this->getRobot();
8787
$this->access['referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "Direct";
8888
$this->access['time'] = time();
89-
$this->access['ip'] = $this->getIP();
89+
return $this;
9090
}
9191

92-
/** Will get the browser */
9392
private function getBrowser()
9493
{
9594
foreach ($this->browsers as $regex => $name) {
9695
if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) {
9796
return $name;
9897
}
9998
}
100-
return "Unknown";
99+
return "Unknown - " . $_SERVER['HTTP_USER_AGENT'];
101100
}
102101

103-
/** Will get the browser's version */
104102
private function getBrowserVersion()
105103
{
106104
$data = explode("/", $_SERVER['HTTP_USER_AGENT']);
107105
return $data[count($data) - 1];
108106
}
109107

110-
/** Will get the system's OS */
111108
private function getOS()
112109
{
113110
foreach ($this->OS as $regex => $name) {
114111
if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) {
115112
return $name;
116113
}
117114
}
118-
return "Unknown";
115+
return "Unknown - " . $_SERVER['HTTP_USER_AGENT'];
119116
}
120117

121-
/** Will check if is a robot */
122118
private function getRobot()
123119
{
124120
foreach ($this->crawlers as $regex => $name) {
125121
if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) {
126122
return $name;
127123
}
128124
}
129-
return false;
125+
return "Unknown - " . $_SERVER['HTTP_USER_AGENT'];
130126
}
131127

132-
/** Will get the IP */
133-
private function getIP()
134-
{
135-
return isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
136-
}
137-
138-
/** Return an Array with the collected info */
139128
public function getInfo()
140129
{
141130
return $this->access;

0 commit comments

Comments
 (0)