PHPBuilder - Browser's language detection



RSS Twitter
Snippets Other

Browser's language detection

by: Rene Nieuwburg
|
October 10, 2001

Version: 0.01

Type: Sample Code (HOWTO)

Category: Other

License: GNU General Public License

Description: Redirects to the right translation of your site, dependent on the browsers language settings. It takes into account the order of user's language preference.



<?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;
?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Rene Nieuwburg

Comment:



Comment:

(Maximum characters: 1200). You have characters left.