想问,但可能这个问题是重复的。很抱歉,其他问题的答案在我的情况下都不起作用。
<标题>我有一个服务器apache作为webserver运行php+7.4与默认设置和certbot作为SSL与公共IP 192.168.1.11,我想检索客户端打开我的网站,例如域news.test.com的IP。Test.com域本身有一个公共IP地址示例123.100.1.10。我如何获得打开news.test.com域的客户端ip ?
<标题>已经做我已经这样做了,以获得IP
public static function get_ip() {
$mainIp = '';
if (getenv('HTTP_CLIENT_IP'))
$mainIp = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$mainIp = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$mainIp = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$mainIp = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$mainIp = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$mainIp = getenv('REMOTE_ADDR');
else
$mainIp = 'UNKNOWN';
return $mainIp;
}
<标题>我得到的问题不是我得到的IP客户端,而是从test.com域得到的IP。我已经尝试了另一个互联网连接,并做了一个公共IP测试,但我仍然从test.com获得IP,而不是客户端IP,这是因为我的父域或apache的设置是错误的设置吗?或者有一个错误或其他方式获得客户端IP。
标题>标题> 标题>请尝试使用HTTP_CF_CONNECTING_IP
public static function get_ip() {
$mainIp = '';
if (getenv('HTTP_CF_CONNECTING_IP'))
$mainIp = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$mainIp = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$mainIp = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$mainIp = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$mainIp = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$mainIp = getenv('REMOTE_ADDR');
else
$mainIp = 'UNKNOWN';
return $mainIp;
}