ciao,
io ho questo script che reindirizza l'utente alla pagina index in base alla lingua installata sul browser. cioè se l'utente ha un browser con installata la lingua inglese, viene indirizzato alla index in inglese, etc.
questo è lo script:
codice:
<?php
$default = 'eng/index.htm';
$redirect = array('fr' => 'fra/index.htm',
'it' => 'ita/index.htm',
'es' => 'esp/index.htm',
'pt' => 'por/index.htm', );
## / 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'];
//echo $lang_list ;exit();
$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();
}
?>
la domanda : con php è possibile inidividuare la lingua del browser SOLO se ne ho installata una, oppure è possibile far individuare la lingua dal semplice fatto che ad esempio ho il browser in italiano?
grazie per la risposta