PHP $_SERVER['REMOTE_ADDR'] 空 [英] PHP $_SERVER['REMOTE_ADDR'] empty
问题描述
不知何故 $_SERVER['REMOTE_ADDR']
返回一个空字符串,我在多个服务器上运行相同的代码(作为脚本的一部分)并且它在其他任何地方都可以使用,它们都是相同的设置.
Somehow $_SERVER['REMOTE_ADDR']
returns an empty string, i have the same code (as part of a script) running on multiple servers and it works everywhere else, they are all the same setup.
奇怪的是,当我重新启动 apache 并加载页面时,它只工作一次,如果我重新加载站点 + 之后所有时间,它都是空的.我让其他人试过,结果一样,空的.
The weird thing is, when I restart apache and load the page, it works exactly once, if I reload the site + all the times after that, it's empty. I've had other people try, same result, empty.
有人建议这是 IPv6 配置的问题,我现在已经完全禁用了 IPv6,但问题仍然存在.
someone suggested it was something with IPv6 configuration, I have now completely disabled IPv6 but the problem persists.
推荐答案
如果你在代理服务器后面,你可以使用 $_SERVER['HTTP_X_FORWARDED_FOR']
或 $_SERVER['HTTP_CLIENT_IP']
而不是 $_SERVER['REMOTE_ADDR']
.这取决于您的代理的配置方式.
if you're behind a proxy server, you can use $_SERVER['HTTP_X_FORWARDED_FOR']
or $_SERVER['HTTP_CLIENT_IP']
instead of $_SERVER['REMOTE_ADDR']
.
this will depends on how your proxy is configured.
这篇关于PHP $_SERVER['REMOTE_ADDR'] 空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!