Apache geoip 不起作用:PHP 致命错误:未捕获错误:未定义常量“HTTP_X_FORWARDED_FOR”

Apache geoip 不起作用:PHP 致命错误:未捕获错误:未定义常量“HTTP_X_FORWARDED_FOR”

测试geoip.php

<html>
<head>
<title>What is my IP address - determine or retrieve my IP address</title>
</head>
<body>
<?php
if (getenv('HTTP_X_FORWARDED_FOR')) { {
$pipaddress = getenv(HTTP_X_FORWARDED_FOR);
$ipaddress = getenv(REMOTE_ADDR);
echo "Your Proxy IP address is : ".$pipaddress. " (via $ipaddress) " ;
} else {
$ipaddress = getenv(REMOTE_ADDR);
echo "Your IP address is : $ipaddress";
}
$country = getenv(GEOIP_COUNTRY_NAME);
$country_code = getenv(GEOIP_COUNTRY_CODE);
echo "<br/>Your country : $country ( $country_code ) ";
?>
</body>
</html>

阿帕奇/2.4

答案1

$pipaddress = getenv(HTTP_X_FORWARDED_FOR);
$ipaddress = getenv(REMOTE_ADDR);

引用你的字符串。

$pipaddress = getenv('HTTP_X_FORWARDED_FOR');
$ipaddress = getenv('REMOTE_ADDR');

相关内容