如何显示IPv4中显示:: 1的IP地址 [英] how to show The IP address in IPv4 which show ::1 in the web page

查看:995
本文介绍了如何显示IPv4中显示:: 1的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示计算机客户端的IP地址。但在我的计算机中运行localhost只显示:: 1。如果我在localhost中运行,它应该显示127.0.0.1。那么如何在IPv4中显示IP地址。因为我在另一篇文章中读到了:: 1是在IPv6中。这是我的代码:

I want to show the IP address of the computer's client. But in my computer which running in localhost show only "::1" . If i run in the localhost, it should be show 127.0.0.1. So how to show the IP address especially in IPv4. Because I read in another article that the ::1 is in IPv6. Here is my code :

function get_ip()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

$ip = get_ip(); 

echo $ip;

给我帮助解决这个问题。谢谢。

Give me help to fix this. Thank You.

推荐答案

如果您希望Web服务器看到您从127.0.0.1连接,则必须通过IPv4连接。尝试导航到 http://127.0.0.1 而不是 http:// localhost 。如果您通过IPv6连接,那么当然 Web服务器将报告IPv6地址。

If you want the web server to see you connecting from 127.0.0.1 then you must connect via IPv4. Try navigating to http://127.0.0.1 instead of http://localhost. If you are connecting via IPv6 then of course the web server will report an IPv6 address.

这篇关于如何显示IPv4中显示:: 1的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆