【发布时间】:2013-03-25 09:32:41
【问题描述】:
我正在尝试在我的 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);
我认为因为脚本是从模板执行的,所以每次加载模板文件时都会执行,所以在重定向时它会继续执行这个脚本。
【问题讨论】:
-
如果 /fr 或很可能我们 (example.com) 有相同的脚本,请在重定向之前检查您当前的位置,否则您将永远重定向...
-
你有这方面的示例脚本吗?
标签: php redirect joomla2.5 geoip