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
Moderator: General Moderators
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;
}
}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;
}