douji5746 2013-06-25 22:05
浏览 128

如何在PHP中找到我的真实IP地址(获取服务器的IP而不是访问者的IP)[重复]

This question already has an answer here:

How do I find my real IP address?

If I do:-

$_SERVER['REMOTE_ADDR']

It gives me wrong IP Address (157.191.122.36), which I've checked as it gives me same values even when my site is accessed through different locations and countries.

This place somehow, gives me the right IP (64.74.66.230) at http://www.whatismyip.com/, but I can't get the same value through the above PHP code.

EDIT

I tried the URL mentioned in the comment. None of the solutions worked for me. It is clear now though that ehen using $_SERVER["REMOTE_ADDR"], I get the server's IP address rather than the visitor's.

</div>
  • 写回答

1条回答 默认 最新

  • doutizong8099 2013-06-25 22:24
    关注

    $_SERVER['REMOTE_ADDR'] is the only reliable IP address you'll get - it's extracted directly from the TCP stack and is where the current connection was established from. This means if the user is connecting via a proxy, you'll get the proxy's address, not the user's.

    Any of the other header-based ones are unreliable, as HTTP headers are trivial to forge. You can use the information from them, if you'd like, as long as you don't TRUST it.

    source: definitive way to get user ip address php

    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入