php之IP
原创
©著作权归作者所有:来自51CTO博客作者zlixing的原创作品,请联系作者获取转载授权,否则将追究法律责任
常用的获取客户端的IP地址的方法:
常用的获取客户端的IP地址的方法:
1)
1 function getRemoteIp(){
2
3 if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
4
5 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
6
7 }
elseif(isset($_SERVER['HTTP_CLIENT_IP'])){
8
9 $ip = $_SERVER['HTTP_CLIENT_IP'];
10
11 }
elseif(getenv('HTTP_X_FORWARDED_FOR')){
12
13 $ip = getenv('HTTP_X_FORWARED_FOR');
14
15 }
elseif(getenv('HTTP_CLIENT_IP')){
16
17 $ip = getenv('HTTP_CLIENT_IP');
18
19 }
elseif($_SERVER['REMOTE_ADDR']){
20
21 $ip = $_SERVER['REMOTE_ADDR'];
22
23 }
24 else{
25
26 $ip = null;
27
28 }
29
30 return $ip;
31 }
服务器(Linux)获取公网IP:
curl ifconfig.me
curl http://members.3322.org/dyndns/getip
curl http://icanhazip.com
curl ident.me
curl http://ipecho.net/plain
curl http://whatismyip.akamai.com
...