php获取客户机真实ip
1 <?php 2 function getIPaddress() 3 { 4 5 $IPaddress=''; 6 7 if (isset($_SERVER)){ 8 9 if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){ 10 11 $IPaddress = $_SERVER["HTTP_X_FORWARDED_FOR"]; 12 13 } else if (isset($_SERVER["HTTP_CLIENT_IP"])) { 14 15 $IPaddress = $_SERVER["HTTP_CLIENT_IP"]; 16 17 } else { 18 19 $IPaddress = $_SERVER["REMOTE_ADDR"]; 20 21 } 22 23 } else { 24 25 if (getenv("HTTP_X_FORWARDED_FOR")){ 26 27 $IPaddress = getenv("HTTP_X_FORWARDED_FOR"); 28 29 } else if (getenv("HTTP_CLIENT_IP")) { 30 31 $IPaddress = getenv("HTTP_CLIENT_IP"); 32 33 } else { 34 35 $IPaddress = getenv("REMOTE_ADDR"); 36 37 } 38 39 } 40 41 return $IPaddress; 42 43 } 44 $IPaddress=getIPaddress(); 45 46 echo $IPaddress;