4
4
* Access class
5
5
*
6
6
* [CHANGELOG]
7
- * 2021-08-03 -> Class created
7
+ * 2021-03-08 -> Class created
8
+ * 2021-03-11 -> Added getIP() method
8
9
*/
9
10
10
11
class Access
@@ -85,8 +86,10 @@ public function __construct()
85
86
$ this ->access ['robot ' ] = $ this ->getRobot ();
86
87
$ this ->access ['referer ' ] = isset ($ _SERVER ['HTTP_REFERER ' ]) ? $ _SERVER ['HTTP_REFERER ' ] : "Direct " ;
87
88
$ this ->access ['time ' ] = time ();
89
+ $ this ->access ['ip ' ] = $ this ->getIP ();
88
90
}
89
91
92
+ /** Will get the browser */
90
93
private function getBrowser ()
91
94
{
92
95
foreach ($ this ->browsers as $ regex => $ name ) {
@@ -97,12 +100,14 @@ private function getBrowser()
97
100
return "Unknown " ;
98
101
}
99
102
103
+ /** Will get the browser's version */
100
104
private function getBrowserVersion ()
101
105
{
102
106
$ data = explode ("/ " , $ _SERVER ['HTTP_USER_AGENT ' ]);
103
107
return $ data [count ($ data ) - 1 ];
104
108
}
105
109
110
+ /** Will get the system's OS */
106
111
private function getOS ()
107
112
{
108
113
foreach ($ this ->OS as $ regex => $ name ) {
@@ -113,6 +118,7 @@ private function getOS()
113
118
return "Unknown " ;
114
119
}
115
120
121
+ /** Will check if is a robot */
116
122
private function getRobot ()
117
123
{
118
124
foreach ($ this ->crawlers as $ regex => $ name ) {
@@ -123,6 +129,13 @@ private function getRobot()
123
129
return false ;
124
130
}
125
131
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 */
126
139
public function getInfo ()
127
140
{
128
141
return $ this ->access ;
0 commit comments