php怎么获取IPV6的地址?用$_SERVER['REMOTE_ADDR']可

2019-01-02 21:19发布

如题,php怎么获取IPV6的地址?用$_SERVER['REMOTE_ADDR']可以吗?

标签: ipv6
1条回答
佑你喜乐
2楼-- · 2019-01-02 21:53

if (isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (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");
} else if (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
} else {
$realip = getenv("REMOTE_ADDR");
}
}
return $realip;

查看更多
登录 后发表回答