【问题标题】:Joomla GEOIP Maxmind redirect loopJoomla GEOIP Maxmind 重定向循环
【发布时间】: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


【解决方案1】:

试试这个:

   $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/ 目录中运行

【讨论】:

  • 它停留在一个循环中,啊。所以浏览器说它有很多连接。并且页面不加载。脚本需要检查脚本是否已经执行。
  • 抱歉,您至少可以回显一下地址吗?让我们检查一下。
猜你喜欢
  • 2012-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多