Page 1 of 1
country and language detection
Posted: Tue Aug 10, 2004 4:13 am
by pppswing
Hello,
I would like to know if there is already some php script that detect country and language. Language of the browser should be easy to find but country depends on many more facts.
Thanks

Posted: Tue Aug 10, 2004 5:03 am
by timvw
To get the languages a browser accepts:
Code: Select all
function getLanguages()
{
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$parts = preg_split("/;/",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$langs = preg_split("/,/",$parts[0]);
return $langs;
}
else
{
return null;
}
}
To get the country (i know you could also have a look at an eventual http_referer etc) i use geoip:
Code: Select all
function getCountry()
{
require_once('geoip.inc');
$address = $_SERVER['REMOTE_ADDR'];
$gi = geoip_open('GeoIP.dat',GEOIP_STANDARD);
$countrycode = geoip_country_code_by_addr($gi,$address);
geoip_close($gi);
return $countrycode;
}