PHP - Redirect depending on specific language

Ask a question







Many sites require that you choose the language by clicking on an icon for the country. It is possible to detect the default language of the visitor through the information provided by the browser (languages: $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE']:


<?
if (!isset($Language)) {
$Language = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$Language = strtolower(substr(chop($Language[0]),0,2));
}
?>


Depending on the language of your visitor you can,:
  • The redirect to a specific page:


<? else {
header("Location: /index.php?Language=en");
}  ?>
  • Include a configuration file containing translations of the selected language:

<? 
include("language-".$Langue.".inc.php");
 ?>

PHP - Detect the display resolution
PHP - Checking the format of an email address