Reputation: 2233
I am developing a Q/A forum on sports. How do i get the timezone of logged in user so as to post his/her queries according to that timezone. Currently I am doing this
Javascript
var current_date = new Date(); var clock=current_date.getTimezoneOffset() / 60; gmt= -1 * clock;
$.post("receive.php",{gmt:gmt});
Receive.php
<?php // set timezone
if(isset($_POST['gmt']))
{
$_SESSION['timezone']=$_POST['gmt']*60*60;
}
?>
But it won't work for those users who have diabled Javascript. Is there a better solution?
Upvotes: 1
Views: 1066
Reputation: 22518
One solution could be to :
1.Retrieve the ip of your user
$ipaddress = $_SERVER["REMOTE_ADDR"];
2.Analyse the ip address using a geolocation ip database.
3.Get the timezone in this location
Upvotes: 2