$ _SERVER ['REMOTE_ADDR']没有返回IP地址 [英] $_SERVER['REMOTE_ADDR'] is not returning ip address

查看:76
本文介绍了$ _SERVER ['REMOTE_ADDR']没有返回IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php中使用$_SERVER['REMOTE_ADDR']查找客户端的ip address.

I am using $_SERVER['REMOTE_ADDR'] in php to find client's ip address.

$ipaddress=$_SERVER['REMOTE_ADDR'];

echo $ipaddress;

返回:: 1

我也尝试了以下代码,但这也给了我相同的结果.

I also tried the following code,but that gives me same result as well.

if ($_SERVER['HTTP_CLIENT_IP'])
    $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
    $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
    $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
    $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
    $ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
    $ipaddress = $_SERVER['REMOTE_ADDR'];
else
    $ipaddress = 'UNKNOWN';

我做错了什么?如何让客户获得IP地址?

What am I doing wrong?How can I get clients ip?

我会使用ip通过ipinfo.io查找客户端的位置.

I would use the ip to find client's location via ipinfo.io.

感谢您的时间.

推荐答案

::1是实际IP.这是一个ipv6地址(即本地主机).如果您使用的是ipv4,则为127.0.0.1.

::1 is the actual IP. It is an ipv6 address (i.e. localhost). If you were using ipv4 it would be 127.0.0.1.

如果要获取其他IP地址,则需要通过其他网络接口连接到服务器.

If you want to get a different IP address, then you'll need to connect to the server through a different network interface.

这篇关于$ _SERVER ['REMOTE_ADDR']没有返回IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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