CloudWeaver



Jul
8
retrieve client browser lang setting with php

I promised a client I would give him a little PHP script to help him deal with internationalization (french/english visitors) of his website. So, here is a very simple way to retrieve your visitor’s browser language setting and fork through a IF clause based on this value :

< ?php
#we retreive the language
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);


#if french $lang=fr, english $lang=en
if ( $lang==”fr” ) {
echo “ceci est la version francaise”;
}
else {
echo “other language”;
}

?>

This is not meant to be the ‘best’ way or the ‘easiest’, it is simply the way I would do it for a small project. If you got a better way, feel free to post it in the comment section of this post !

tagged with : , , , , , , | permalink

Leave a Reply

© 2010 CloudWeaver | Theme by DemusDesign, Theme Lab, and Best Linux Web Hosting | Powered by WordPress