PHP - Redirect depending on specific language

December 2016

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:


Related :

This document entitled « PHP - Redirect depending on specific language » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.