PHP标头位置重定向循环


PHP header location redirect loop

我在这里找到了这个php地理重定向脚本

代码如下:

<?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是基于美国的重定向脚本应该重定向到自己,并留在主页上。相反,我得到一些重定向循环和页面不能正确加载。

如果location为US,则无需重定向:

<?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');
}
?>