当前位置:Gxlcms > PHP教程 > php下获取客户端ip地址的函数_PHP教程

php下获取客户端ip地址的函数_PHP教程

时间:2021-07-01 10:21:17 帮助过:6人阅读

代码如下:
function getip() {
$IP=getenv('REMOTE_ADDR');
$IP_ = getenv('HTTP_X_FORWARDED_FOR');
if (($IP_ != "") && ($IP_ != "unknown")) $IP=$IP_;
return $IP;
}

下面这个比较好的
代码如下:
function getIP()
{
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");
}
}
return $realip;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321511.htmlTechArticle 代码如下:

function getip() { $IP=getenv('REMOTE_ADDR'); $IP_ = getenv('HTTP_X_FORWARDED_FOR'); if (($IP_ != "") ($IP_ != "unknown")) $IP=$IP_; return $IP; } 下面这...

人气教程排行