Home >php教程 >php手册 >获取客户端IP

获取客户端IP

WBOY
WBOYOriginal
2016-06-21 09:07:201024browse

客户端


function iptype1 () {
if (getenv("HTTP_CLIENT_IP")) {
   return getenv("HTTP_CLIENT_IP");
}
else {
   return "none";
}
}
function iptype2 () {
if (getenv("HTTP_X_FORWARDED_FOR")) {
   return getenv("HTTP_X_FORWARDED_FOR");
}
else {
   return "none";
}
}
function iptype3 () {
if (getenv("REMOTE_ADDR")) {
   return getenv("REMOTE_ADDR");
}
else {
   return "none";
}
}
function ip() {
$ip1 = iptype1();
  $ip2 = iptype2();
$ip3 = iptype3();
if (isset($ip1) && $ip1 != "none" && $ip1 != "unknown") {
   return $ip1;
}
elseif (isset($ip2) && $ip2 != "none" && $ip2 != "unknown") {
   return $ip2;
}
elseif (isset($ip3) && $ip3 != "none" && $ip3 != "unknown") {
   return $ip3;
}  
  else {
  return "none";
}
}

Echo ip();
?>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn