44 * Access class
55 *
66 * [CHANGELOG]
7- * 2021-08-03 -> Class created
7+ * 2021-03-08 -> Class created
8+ * 2021-03-11 -> Added getIP() method
89 */
910
1011class Access
@@ -85,8 +86,10 @@ public function __construct()
8586 $ this ->access ['robot ' ] = $ this ->getRobot ();
8687 $ this ->access ['referer ' ] = isset ($ _SERVER ['HTTP_REFERER ' ]) ? $ _SERVER ['HTTP_REFERER ' ] : "Direct " ;
8788 $ this ->access ['time ' ] = time ();
89+ $ this ->access ['ip ' ] = $ this ->getIP ();
8890 }
8991
92+ /** Will get the browser */
9093 private function getBrowser ()
9194 {
9295 foreach ($ this ->browsers as $ regex => $ name ) {
@@ -97,12 +100,14 @@ private function getBrowser()
97100 return "Unknown " ;
98101 }
99102
103+ /** Will get the browser's version */
100104 private function getBrowserVersion ()
101105 {
102106 $ data = explode ("/ " , $ _SERVER ['HTTP_USER_AGENT ' ]);
103107 return $ data [count ($ data ) - 1 ];
104108 }
105109
110+ /** Will get the system's OS */
106111 private function getOS ()
107112 {
108113 foreach ($ this ->OS as $ regex => $ name ) {
@@ -113,6 +118,7 @@ private function getOS()
113118 return "Unknown " ;
114119 }
115120
121+ /** Will check if is a robot */
116122 private function getRobot ()
117123 {
118124 foreach ($ this ->crawlers as $ regex => $ name ) {
@@ -123,6 +129,13 @@ private function getRobot()
123129 return false ;
124130 }
125131
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 */
126139 public function getInfo ()
127140 {
128141 return $ this ->access ;
0 commit comments