0

joomla 2.5 インストールに Geoip サービスを実装しようとしています。

私が欲しいのは、ウェブサイト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);

スクリプトはテンプレートから実行されるため、テンプレート ファイルが読み込まれるたびに実行されるため、リダイレクト時にこのスクリプトが継続的に実行されると思います。

4

1 に答える 1

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/ ディレクトリで実行されると想定されていることに注意してください。

于 2013-03-25T09:55:24.133 に答える