【发布时间】:2015-11-01 21:09:51
【问题描述】:
我发现了这个 php 地理重定向脚本 here
代码如下:
<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
// create a variable for the country code
$var_country_code = $geoplugin->countryCode;
// redirect based on country code:
if ($var_country_code == "US") {
header('Location: http://domain.com');
}
else if ($var_country_code == "NL") {
header('Location: http://domain.com/nl');
}
else if ($var_country_code == "FR") {
header('Location: http://domain.com/fr');
}
else {
header('Location: http://domain.com/int');
}
?>
我把这段代码放在了我的 index.php 的开头。
我遇到并试图解决的问题是,当我的 IP 是基于美国的重定向脚本时,应该重定向到自身并留在主页上。相反,我得到了一些重定向循环,并且页面无法正确加载。
【问题讨论】:
-
如果您在美国,并且您转到domain.com,检查器正在与美国进行比较并将您永远重定向到domain.com。尝试为我们添加位置。 domain.com/us
-
但我想将我们重定向到它自己 (domain.com) 而不是创建单独的域 domain.com/us
-
然后,尝试检查用户是否访问了不同的域.. if($code=='US' && $_SERVER['REQUEST_URI'])