forse ti può esser utile
Codice PHP:
<?php
/*
redirect to the browser language (if possible), else to the default language
*/
## config ##
$default = '/fr/';
$redirect = array('fr' => '/fr/',
'de' => '/de/');
## / config ##
// get the language string proposed by the browser if there is one
function lang_from_browser() {
// it;q=1.0,fr;q=0.9,en;q=0.8 OR fr-ch
$lang_list = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang_block = explode(',', $lang_list);
$lang_ar = array();
foreach ($lang_block as $t) {
array_push($lang_ar, strtolower(substr(trim($t), 0,2)));
}
return $lang_ar;
}
// redirect to the browser language if there is one
function redirect($lang){
global $redirect;
if(count($lang) > 0){
foreach($lang as $l){
if(array_key_exists($l,$redirect)){
header('Location: '.$redirect[$l]);
die();
}
}
}
return true;
}
## redirect ##
if(redirect(lang_from_browser())){
header('Location: '.$default);
die();
}
?>