$ _SERVER ['REMOTE_ADDR']没有给出正确的IP地址 [英] $_SERVER['REMOTE_ADDR'] not giving the right ip address
问题描述
我正在使用PHP创建一个表单,我想记录用户的IP地址。这是我使用的代码片段:
I'm making a form with PHP and I want to keep record of the User's IP Addresses. This is the snip-it of code I used:
<input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
当我在XAMPP中打开代码并读取源代码时,该值的IP地址不同于我的是什么:
When I open the code up in XAMPP and read the source, the value had an IP address different than what was mine:
<input type="hidden" name="ip" value="::1" />
当我在localhost(XAMPP)中使用时,这个IP地址通常会发生吗?
如果没有,是否有其他方法可以获取用户的IP地址?
Does this IP address normally happen when I use it in a localhost (XAMPP)?
If not, are there any alternatives into grabbing the user's IP address?
推荐答案
< input type =hiddenname =ipvalue =<?php echo $ _SERVER ['REMOTE_ADDR'];?> />
不要这样做。提交表单时,从 $ _ SERVER
获取请求。在生成表单并将其存储在表单中时获取它只是让人们有机会更改它。
Don't do that. Get the request from $_SERVER
when the form is submitted. Getting it when the form is generated and storing it in the form just gives people the opportunity to change it.
当我在localhost(XAMPP)中使用它时,通常会发生此IP地址吗?
是。当您从localhost请求页面时,获取本地IP(IPv6)地址是正常的。
Yes. Getting the local IP (IPv6) address is normal when you request a page from localhost.
这篇关于$ _SERVER ['REMOTE_ADDR']没有给出正确的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!