PHP $_SERVER['REMOTE_ADDR'] 空 [英] PHP $_SERVER['REMOTE_ADDR'] empty

查看:38
本文介绍了PHP $_SERVER['REMOTE_ADDR'] 空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知何故 $_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆