简体   繁体   English

来自不同国家的不同Drupal主页

[英]Different Drupal front page from different country

I have a drupal site, and i want to redirecting visitors to a different page based on the country. 我有一个drupal网站,我想根据国家将访问者重定向到另一个页面。 I have this code: 我有以下代码:

require_once "Net/GeoIP.php";
$geoip = Net_GeoIP::getInstance("Net/GeoIP.dat");
try {
    $geocode = $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']);
} catch (Exception $e) {
    $geocode = 'EN';
}
switch ($geocode) {
    case 'HU':
        header('Location: http://www.example.com/hu');
        break;
    case 'GB':
        header('Location: http://www.example.com/en');
        break;
    case 'AT':
        header('Location: http://www.example.com/at');
        break;
    case 'CY':
        header('Location: http://www.example.com/cy');
        break;
    case 'DE':
        header('Location: http://www.example.com/de');
        break;
    case 'NL':
        header('Location: http://www.example.com/nl');
        break;
    case 'CH':
        header('Location: http://www.example.com/ch');
        break;
    case 'ES':
        header('Location: http://www.example.com/es');
        break;
    case 'US':
        header('Location: http://www.example.com/us');
        break;
    default:
        header('Location: http://www.example.com/en');
}

This works well on plain php file. 这在纯php文件上效果很好。 How can i this in drupal? 我如何在Drupal中使用? How can i redirect the visitors to the proper node? 如何将访客重定向到适当的节点?

You may want to use http://drupal.org/project/ip2locale 您可能要使用http://drupal.org/project/ip2locale

It supports GeoIP. 它支持GeoIP。

I don't understand neither why not using an existing solution but still: have you tried putting your snippet inside page.tpl.php? 我既不明白为什么不使用现有解决方案,但是仍然:您是否尝试过将代码段放入page.tpl.php中? Just make sure the path to the required library is correct. 只需确保所需库的路径正确即可。 You might wanna put Net/GeoIP.php inside your sites/all/libraries folder and thus change require_once "Net/GeoIP.php" to require_once "../../libraries/Net/GeoIP.php" . 您可能想将Net / GeoIP.php放入您的sites / all / libraries文件夹中,然后将require_once“ Net / GeoIP.php”更改为require_once“ ../../libraries/Net/GeoIP.php” This is assuming that your page.tpl.php is located inside sites/all/themes/ yourtheme / 假设您的page.tpl.php位于sites / all / themes / yourtheme /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM