国家地理位置将我重定向到错误的链接


Country geolocation redirects me to the wrong link?

所以我有这个代码,我的ip来自ph;

<?php
require_once('geoip.inc');
$gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
switch ($country) {
 case 'ph':
     $location = 'url/ph/index.php';
     break;
 case 'us':
     $location = 'url/intl/index.php';
     break;
 case 'in':
     $location = 'url/intl/index.php';
     break;
 default:
     $location = 'url/intl/index.php';
     break;
 }
 header('Location: '.$location.'');
 ?>  

每当我尝试使用该代码并使用我自己的homeip(菲律宾)访问我的网站时,它总是在intl/index.php页面上重定向我。所有东西都已经在我的主目录中了,比如geoap.inc和geoap.dat。它们都已经在根文件夹中了。

有人知道我在这里缺了什么吗?非常感谢。

函数geoap_country_code_by_addr以大写形式返回国家代码,因此PH、US、in等。当您输入小写国家代码时,它总是包括默认数据。

所以需要像一样将控制代码更改为大写

<?php
require_once('geoip.inc');
$gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
switch ($country) {
 case 'PH':
     $location = 'url/ph/index.php';
     break;
 case 'US':
     $location = 'url/intl/index.php';
     break;
 case 'IN':
     $location = 'url/intl/index.php';
     break;
 default:
     $location = 'url/intl/index.php';
     break;
 }
 header('Location: '.$location.'');
 ?>