Zend - The PHP Company




Menus & Navigation

Add Code


Language detection  

Type: code fragment
Added by: Comunica2
Entered: 10/10/2001
Last modified: 31/10/2000
Rating: - (fewer than 3 votes)
Views: 8657
Language is detected according to the browser's language preference settings. User is automatically redirected to preferred language or to a default language


<?php
$lang
=strtok($HTTP_ACCEPT_LANGUAGE,","); //language codes are comma delimited
while ($lang){
 if (
strstr($lang,"en")){ //if there is "en" in it
  
header ("Location: http://your.domain.com/english/"); 
  exit;}
 if (
strstr($lang,"es")){
  
header ("Location: http://your.domain.com/castellano/"); 
  exit;}
 if (
strstr($lang,"nl"){
  
header ("Location: http://your.domain.com/nederlands/"); 
  exit;}
 if 
ereg((strstr($lang,"de"){
  
header ("Location: http://your.domain.com/deutsch/"); 
  exit;}
 
$lang=strtok(",");}//next token and end of while
header ("Location: http://your.domain.com/english/"); // default relocation in case nothing got detected
exit;
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories