1 public static function getIp()
2 {
3 if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
4 {
5 $ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
6 }
7 elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
8 {
9 $ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
10 }
11 elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])
12 {
13 $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
14 }
15 elseif (getenv("HTTP_X_FORWARDED_FOR"))
16 {
17 $ip = getenv("HTTP_X_FORWARDED_FOR");
18 }
19 elseif (getenv("HTTP_CLIENT_IP"))
20 {
21 $ip = getenv("HTTP_CLIENT_IP");
22 }
23 elseif (getenv("REMOTE_ADDR"))
24 {
25 $ip = getenv("REMOTE_ADDR");
26 }
27 else
28 {
29 $ip = "Unknown";
30 }
31 if(strpos($ip, ',') !== false){
32 $ip = explode(',', $ip);
33 $ip = reset($ip);
34 }
35 return $ip;
36 }
37
转载自:https://www.cnblogs.com/520blog/p/5789337.html
仅供个人学习,如有疑问,请联系。