从用户IP地址获取位置

编程入门 行业动态 更新时间:2024-10-11 19:20:57
本文介绍了从用户IP地址获取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从使用的IP地址获取位置。有很多关于如何做到这一点的主题。我真的喜欢这个,它的工作原理非常清晰。 示例中使用的IP地址在德国的某处找到位置,但是当我使用我的IP地址(192.168.0.7)时,所有内容都会以未知方式返回。当网站只在线时,我不会使用我的IP地址,我将使用PHP找到用户的IP地址。

I am trying to get a location from a uses IP address. There is a lot of topics on how to do this. I really like this one, it works and is very clear. The IP address used in the example finds the location somewhere in germany, but when I use my IP address (192.168.0.7) everything comes back as unknown. When the site is only online I wouldn't be using my IP address I would be finding the users IP address using PHP.

if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } $ip = '192.168.0.7'; //replace with my IP address

我也遇到了此网站找到我的IP地址,除了数字不同外,这是非常准确的。 2.126.219.101

I have also came across this site which finds my IP address, which is quite accurate except the numbers are different. 2.126.219.101

有没有办法可以测试我在localhost上使用上述方法获取我的IP地址,或者我的IP地址有问题。

Is there a way I can test what I have on localhost to obtain my IP address using the above method or is there something wrong with my IP address.

推荐答案

192.168.0.7 是你的私人 IP地址。它仅在您的本地(家庭,工作......)网络中有效。因为它仅在您的本地网络内有效,所以它不能用于位置。事实上,现在世界上可能有数百万台其他计算机在自己的网络中也拥有这个私有IP地址。

192.168.0.7 is your private IP address. It is only valid within your local (home,work...) network. Because it is only valid inside your local network, it cannot be used for location. In fact, there are probably millions of other computers in the world right now that also have this private IP address within their own networks.

2.126。 219.101 是您的公共 IP地址。至于本地网络以外的任何机器,这都是您的IP地址。它可用于指示位置。

2.126.219.101 is your public IP address. As far any machine outside of your local network is concerned, that is your IP address. It can be used to give an indication of location.

更多推荐

从用户IP地址获取位置

本文发布于:2023-11-28 08:59:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   地址   用户   IP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!