0
Thanks

A few words of thanks would be greatly appreciated.

PHP - Redirect depending on specific language








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");
 ?>
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team

Related

Published by . Latest update on by jak58.

This document, titled "PHP - Redirect depending on specific language," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

0 Comments