【发布时间】:2016-04-13 08:51:43
【问题描述】:
所以我有这个代码,我的 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.'');
?>
每当我尝试使用该代码访问我的网站并使用我自己的家庭 IP(菲律宾)时,它都会不断地在 intl/index.php 页面上重定向我。一切都在我的主目录中,就像 geoip.inc 和 geoip.dat 一样。它们都已经在根文件夹中了。
有人知道我在这里缺少什么吗?谢谢!
【问题讨论】:
-
您是否验证了要解析到的 $country ?尝试回显/转储/记录该变量。
-
@aynber 嗯抱歉,我该如何记录呢?对这件事真的很陌生。
-
如果您有某种记录功能,请使用它。否则,请执行
var_dump($country)以确保您得到您所期望的。 -
@aynber 我删除了我之前的评论,但我设法记录了它,它说“美国”。 1:blah 2:blahstring(2) “美国”
标签: php redirect geolocation geo