2024-11-30

PHP如何获取IPv6地址及$_SERVER[‘REMOTE_ADDR’]是否可靠?

php如何获取ipv6地址及$_server['remote_addr']是否可靠?

php 获取 ipv6 地址

如何使用 php 获取 ipv6 地址?$_server[‘remote_addr’] 是否可用?

答案

要获取 ipv6 地址,需要考虑以下脚本:

立即学习PHP免费学习笔记(深入)”;

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;
登录后复制

以上就是PHP如何获取IPv6地址及$_SERVER[‘REMOTE_ADDR’]是否可靠?的详细内容,更多请关注php中文网其它相关文章!

https://www.php.cn/faq/1120965.html

发表回复

Your email address will not be published. Required fields are marked *