HTML - How can I determine a web user's time zone?
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
Is there a standard way for a web server to determine what time zone offset a user is in?
From an HTTP header or part of the user-agent description, perhaps?
This question and answers originated from www.stackoverflow.com
Question by Kevin Dente (8/1/2008 12:42:38 AM)
Answer |
timezone.js:
function ajaxpage(){
var url = "timezone.php";
var visitortime = new Date();
vat time = visitortime.getTimezoneOffset()/60;
var page_request = false
if (window.XMLHttpRequest)
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e) {}
}
} else
return false
page_request.onreadystatechange=function() {
loadpage(page_request, containerid)
}
if (bustcachevar)
bustcacheparameter=(url.indexOf("?")!=-1) ? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter+"&time="+time, true)
page_request.send(null) }
function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.write('<meta http-equiv="refresh" content="0;url=http://example.com/"/>');
}
timezone.php:
<?php
session_start();
$_SESSION['time'] = $_GET['time'];
?>
When you want to use it add onLoad="ajaxpage();" to the body tag and it should cause the timezone to be stored in the PHP session variable $_SESSION['time']
Edit: P.S. This is untested.
Answer by Unkwntech
Find More Answers