summaryrefslogtreecommitdiff
path: root/app/Core
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-09-28 09:19:19 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-09-28 09:19:19 -0400
commit9003f830efcdc92865754a5d62e9fd2fea172af7 (patch)
tree52f24c0ac1d0c701b7562087bee33b2a2ad6e281 /app/Core
parent4aa99e949224279ad64be26806e2657e66bf5adf (diff)
Move methods getIpAddress() and getUserAgent() to the Request class
Diffstat (limited to 'app/Core')
-rw-r--r--app/Core/Request.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/Core/Request.php b/app/Core/Request.php
index 09792013..31672ff6 100644
--- a/app/Core/Request.php
+++ b/app/Core/Request.php
@@ -148,4 +148,61 @@ class Request
return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
}
+ /**
+ * Get the user agent
+ *
+ * @static
+ * @access public
+ * @return string
+ */
+ public static function getUserAgent()
+ {
+ return empty($_SERVER['HTTP_USER_AGENT']) ? t('Unknown') : $_SERVER['HTTP_USER_AGENT'];
+ }
+
+ /**
+ * Get the real IP address of the user
+ *
+ * @static
+ * @access public
+ * @param bool $only_public Return only public IP address
+ * @return string
+ */
+ public static function getIpAddress($only_public = false)
+ {
+ $keys = array(
+ 'HTTP_CLIENT_IP',
+ 'HTTP_X_FORWARDED_FOR',
+ 'HTTP_X_FORWARDED',
+ 'HTTP_X_CLUSTER_CLIENT_IP',
+ 'HTTP_FORWARDED_FOR',
+ 'HTTP_FORWARDED',
+ 'REMOTE_ADDR'
+ );
+
+ foreach ($keys as $key) {
+
+ if (isset($_SERVER[$key])) {
+
+ foreach (explode(',', $_SERVER[$key]) as $ip_address) {
+
+ $ip_address = trim($ip_address);
+
+ if ($only_public) {
+
+ // Return only public IP address
+ if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
+ return $ip_address;
+ }
+ }
+ else {
+
+ return $ip_address;
+ }
+ }
+ }
+ }
+
+ return t('Unknown');
+ }
}