php 获取client真实ip

<?php

/**

*获取用户真实IP

*

*@Author:小熊

*@Return:string

*/

functiongetIP()

{

static$realip;

if(isset($_SERVER)){

if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){

$realip=$_SERVER["HTTP_X_FORWARDED_FOR"];

}elseif(isset($_SERVER["HTTP_CLIENT_IP"])){

$realip=$_SERVER["HTTP_CLIENT_IP"];

}else{

$realip=$_SERVER["REMOTE_ADDR"];

}

}else{

if(getenv("HTTP_X_FORWARDED_FOR")){

$realip=getenv("HTTP_X_FORWARDED_FOR");

}elseif(getenv("HTTP_CLIENT_IP")){

$realip=getenv("HTTP_CLIENT_IP");

}else{

$realip=getenv("REMOTE_ADDR");

}

}

相关推荐