2013-03-25 61 views
0

我試圖在我的joomla 2.5安裝上實現Geoip服務。Joomla GEOIP Maxmind重定向循環

我想要的是,網站http://www.example.com重定向到法國語言的http://www.example.com/fr

我已經將maxmind geoip包含在模板文件的標題中。但重定向在循環中執行。

這是我如何執行該文件:

<?php include_once('templates/my_template/geoip/country-redirect.php'); ?> 

這是我的重定向腳本:

$gi = geoip_open('templates/my_template/geoip/GeoIP.dat', GEOIP_MEMORY_CACHE); 
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); 
// prints the country code your visitor is in 
if($country == 'FR') 
{ 
header('Location: http://www.example.com/fr'); 
exit(); 
} 
else if($country == 'US') 
{ 
header('Location: http://example.com'); 
exit(); 
} 
// the end 
geoip_close($gi); 

我想是因爲劇本是由它將執行每次模板文件模板執行被加載,所以在重定向時它會連續執行這個腳本。

+0

如果運行/ FR或最有可能我們( example.com)具有相同的腳本,請在重定向之前檢查您的當前位置,否則您將永遠重定向... – Ihsan 2013-03-25 09:38:29

+0

您是否有此示例腳本? – 2013-03-25 09:45:58

回答

0

試試這個:

$addr = $_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']); 
    $fr = (($addr == 'www.example.com/fr')||($addr == 'example.com/fr')); 
    if((!$fr)&&($country == 'FR')){ // if not at france and country is france 
    header('Location: http://www.example.com/fr'); 
    exit(); // you exit here, so no else required 
    } 
    if(($fr)&&($country == 'US')){ // if at france and country is US 
    header('Location: http://example.com'); 
    exit(); 
    } 

注意,該腳本假設在www.example.com/和www.example.com/fr/目錄

+0

它保持循環,argh。所以瀏覽器說它有很多連接。並且該頁面無法加載。腳本需要檢查腳本是否已經執行。 – 2013-03-25 10:08:56

+0

對不起,你至少可以回顯addr嗎?讓我們檢查一下。 – Ihsan 2013-03-25 10:34:08