不同的浏览器,不同的IP?

发布于 2024-12-15 22:26:55 字数 463 浏览 5 评论 0原文

我通过将 $_SERVER['REMOTE_ADDR'] 的值保存在 MySQL 数据库中来保存用户的 IP 地址。问题是,对于 Firefox 和 Chrome,$_SERVER['REMOTE_ADDR'] 都是 ::1(这意味着 IPv6 中的 localhost),而对于 IE Opera 是 127.0.0.1 (IPv4)。

所以,我的问题是

  • IP 版本是否依赖于浏览器? (我曾经认为这取决于 计算机)

  • 我应该在数据库中创建两个字段,一个用于 IPv4 地址,一个用于 IPv6 地址吗?

  • 我应该将所有 IP 统一为 IPv6 吗?我怎样才能在 PHP 中做到这一点(如果可能的话)?

I'm saving the user's IP addresses by saving the value of $_SERVER['REMOTE_ADDR'] in a MySQL database. Problem is that for both Firefox and Chrome $_SERVER['REMOTE_ADDR'] is ::1 (that means localhost in IPv6) and for IE and Opera is 127.0.0.1 (IPv4).

So, my questions are

  • Are IP versions browser-dependant? (I used to think it depended on
    the computer)

  • Should I create two fields in the database, one for IPv4 addresses and one for IPv6 ones?

  • Should I unify all IPs to IPv6? And how can I do this in PHP (if it's even possible)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

隐诗 2024-12-22 22:26:55
  1. 相当明显 - 您的盒子启用了 IPv6,Firefox/Chrome 在可用时使用 IPv6,而 IE 和 Opera 则不使用(或者默认设置为关闭)。

  2. 将地址存储在足以容纳 IPv6 地址的字符串中。

  3. 不,因为在一般情况下你不能。

  1. Fairly obvious - your box is IPv6-enabled, Firefox/Chrome use IPv6 whenever available, while IE and Opera don't (or it's a off-by-default setting).

  2. Store the address in a string that's long enough to hold an IPv6 address.

  3. No, 'cause in the general case you cannot.

眉目亦如画i 2024-12-22 22:26:55

使用 PHP 函数 inet_pton 将人类可读的 IP 地址转换为其打包表示形式。然后,您可以将每个 IP 地址存储在数据库的 BINARY(16)VARBINARY(16) 字段中。

Use the PHP function inet_pton to convert human readable IP addresses to their packed representation. You can then store each IP address in a BINARY(16) or VARBINARY(16) field in your database.

茶底世界 2024-12-22 22:26:55

浏览器将使用任何可用的东西。这可以是 IPv4 或 IPv6,甚至可以在会话期间更改。最重要的是,请记住,主机可以有许多 IPv6 地址,因此它也可能在会话期间发生变化。

简而言之:不要过多依赖 REMOTE_ADDR 的值:-)

The browser will use whatever is available. This can be IPv4 or IPv6, and that can even change during the session. On top of that keep in mind that a host can have many IPv6 addresses so it might change during the session as well.

In short: don't depend on the value of REMOTE_ADDR too much :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文