i need to define a predefined language, it will be possible to change from Spanish to Portuguese, Spain time is GMT+2 and Portugal GMT+1, the time zone from the server is GMT+2, so i can know from wich country the user is accessing, and define the language that is more convenient. I was thinking about define a cookie and import a file with some php conditions using AJAX.
What do you suggest? Any hints?
It would be more effective to use php's variable $_SERVER['HTTP_ACCEPT_LANGUAGE']
!
Like others suggest, you should use the "accept-language" header.
If for some unknown reason you really want to go through the effort of figuring it out by timezone, you can either look up their country by IP, or with the W3C geolocation API, or through a man in the middle page by writing out some javascript that passes in their time.
session_start();
if($_REQUEST['user_time'])
{
$_SESSION['user_time'] = $_REQUEST['user_time'];
}
if(!isset($_SESSION['user_time']))
{
echo "<script type=\"text/javascript\">";
echo "document.location.href = '?user_time=' + new Date().getTime();";
echo "</script>";
}
else
{
//normal page execution here
}
http://dev.opera.com/articles/view/how-to-use-the-w3c-geolocation-api/
http://googlecode.blogspot.com/2008/08/two-new-ways-to-location-enable-your.html