From b4d9b0e182ea1fe0e63460115bf0802439b14a4c Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Sat, 16 Feb 2013 17:13:19 -0500 Subject: [PATCH] Added method to pull the user's IP Browser::remoteIP(); --- classes/Browser.php | 39 ++++++++++++++++++++++++++++++++++----- jar.php | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/classes/Browser.php b/classes/Browser.php index 9462292..9506456 100644 --- a/classes/Browser.php +++ b/classes/Browser.php @@ -87,6 +87,18 @@ class Browser extends Object return false; } + /** + * Go Home + * + * Alias for `Browser::redirect('/');` + * + * @static + */ + public static function goHome() + { + Browser::redirect('/'); + } + /** * Is Mobile * @@ -126,15 +138,32 @@ class Browser extends Object } /** - * Go Home + * Remote IP * - * Alias for `Browser::redirect('/');` + * Returns the user's IP address. * - * @static + * @return mixed IP address or false if unable to determine */ - public static function goHome() + public static function remoteIP() { - Browser::redirect('/'); + if (!empty($_SERVER['HTTP_CLIENT_IP'])) + { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } + elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) + { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + elseif (isset($_SERVER['REMOTE_ADDR'])) + { + $ip = $_SERVER['REMOTE_ADDR']; + } + else + { + $ip = false; + } + + return $ip; } /** diff --git a/jar.php b/jar.php index 1047a2b..bd21971 100755 --- a/jar.php +++ b/jar.php @@ -392,6 +392,18 @@ class Browser extends Object return false; } + /** + * Go Home + * + * Alias for `Browser::redirect('/');` + * + * @static + */ + public static function goHome() + { + Browser::redirect('/'); + } + /** * Is Mobile * @@ -431,15 +443,32 @@ class Browser extends Object } /** - * Go Home + * Remote IP * - * Alias for `Browser::redirect('/');` + * Returns the user's IP address. * - * @static + * @return mixed IP address or false if unable to determine */ - public static function goHome() + public static function remoteIP() { - Browser::redirect('/'); + if (!empty($_SERVER['HTTP_CLIENT_IP'])) + { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } + elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) + { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + elseif (isset($_SERVER['REMOTE_ADDR'])) + { + $ip = $_SERVER['REMOTE_ADDR']; + } + else + { + $ip = false; + } + + return $ip; } /**