我有一个 drupal 网站,我想根据国家/地区将访问者重定向到不同的页面。我有这个代码:
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');
}
这适用于普通的 php 文件。我怎么能在drupal中这样做?如何将访问者重定向到正确的节点?