Forum Moderators: coopster
<?php
if(strstr($HTTP_ACCEPT_LANGUAGE,"en-us")) {
Header("Location: [test1.com");...]
}
elseif(strstr($HTTP_ACCEPT_LANGUAGE,"fr")) {
Header("Location: [test2.com");...]
}
else {Header("Location: [test.com");...]
}
?>
Or is something in .htaccess better?
[httpd.apache.org...]
<?php
// PHP detect language script.
//check first to see if they've been nice and
//set the language
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
//grab all the languages
$langs=explode(",",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);
//start going through each one
foreach ($langs as $value) {
//select only the first two letters
$choice=substr($value,0,2);
//redirect to the different language page
//based on their first chosen language
switch ($choice) {
case "en":
header("HTTP/1.1 301 Moved Permanently");
header("Location: ./english.html");
exit;
break;
case "fr":
header("HTTP/1.1 301 Moved Permanently");
Header("Location: ./french.html");
exit;
break;
default:
header("HTTP/1.1 301 Moved Permanently");
Header("Location: ./french.html");
exit;
}
}
}
//If the language is not set then use this
//as default
else {
header("HTTP/1.1 301 Moved Permanently");
header("Location: ./french.html");
exit;
}
?> The idea with the above script is not to automatically redirect every page, just to detect the language of the user when hitting the index page. You might want to develop this further, perhaps by adding a cookie and a language preference setting.