簡體   English   中英

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是基於美國的重定向腳本時,應該重定向到其自身並停留在主頁上。 相反,我遇到了一些重定向循環,頁面無法正確加載。

如果位置在美國,則無需重定向:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM