diff --git a/hwe/func.php b/hwe/func.php index e7ea5903..c5a2f6e0 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -1047,7 +1047,7 @@ function increaseRefresh($type = "", $cnt = 1) $logDB = FileDB::db($logPath, $serverPath . '/../f_install/sql/api_log.sql'); - $ip = $_SERVER['REMOTE_ADDR'] ?? 'local'; + $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? 'local'; $date = date('Y-m-d H:i:s'); $logDB->insert('api_log', [ diff --git a/src/sammo/APIHelper.php b/src/sammo/APIHelper.php index 7268d744..1bb51a0d 100644 --- a/src/sammo/APIHelper.php +++ b/src/sammo/APIHelper.php @@ -73,7 +73,7 @@ class APIHelper $logPath = "{$rootPath}/d_log/{$realYearMonth}_api_log.db"; } $logDB = FileDB::db($logPath, __DIR__ . '/../../f_install/sql/api_log.sql'); - $ip = $_SERVER['REMOTE_ADDR'] ?? 'local'; + $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? 'local'; $date = date('Y-m-d H:i:s'); //NOTE: array_merge([], {})의 상황이 가능함. diff --git a/src/sammo/Util.php b/src/sammo/Util.php index dd9227f6..f3e1745e 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -947,31 +947,13 @@ class Util return $flattened; } - /** - * Returns the IP address of the client. - * - * @param boolean $trust_proxy_headers Whether or not to trust the - * proxy headers HTTP_CLIENT_IP - * and HTTP_X_FORWARDED_FOR. ONLY - * use if your server is behind a - * proxy that sets these values - * @return string - */ public static function get_client_ip($trust_proxy_headers = false) { if (!$trust_proxy_headers) { return $_SERVER['REMOTE_ADDR']; } - if (!empty($_SERVER['HTTP_CLIENT_IP'])) { - $ip = $_SERVER['HTTP_CLIENT_IP']; - } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - } else { - $ip = $_SERVER['REMOTE_ADDR']; - } - - return $ip; + return $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? 'local'; } /**