/** * @return array|mixed|string|string[] */ public function getClientIP() { if (@$_SERVER["HTTP_ALI_CDN_REAL_IP"]) { $ip = $_SERVER["HTTP_ALI_CDN_REAL_IP"]; } elseif (@$_SERVER["HTTP_X_FORWARDED_FOR"] ?: false) { $ips = explode(',', $_SERVER["HTTP_X_FORWARDED_FOR"]); $ip = $ips[0]; } elseif (@$_SERVER["HTTP_CDN_SRC_IP"] ?: false) { $ip = $_SERVER["HTTP_CDN_SRC_IP"]; } elseif (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); } elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); } elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); } else { $ip = $_SERVER['REMOTE_ADDR']; } $ip = str_replace(['::ffff:', '[', ']'], ['', '', ''], $ip); return $ip; }
标签:HTTP,FORWARDED,ip,用户,getenv,获取,IP,SERVER From: https://www.cnblogs.com/zhangzhijian/p/18293226