Jump to content
  • Advertisement
Sign in to follow this  
Sonnenblume

[web] PHP: Check users timezone

This topic is 3878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've checked the web and php's own manual, but is there a function which will allow me to check which timezone a given user is in? Im guessing there isnt, but I just thought I would check.

Share this post


Link to post
Share on other sites
Advertisement
A remote user - as in someone accessing the website? There isn't, that information isn't passed in HTTP GET requests.

Aside from asking the user to enter theit time zone, the best you could do would be to lookup their IP address to determine their country, and get the time zone from that. Although that won't always work, and requires a IP -> Country lookup, and as far as I know there's no free databases with that information.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
A remote user - as in someone accessing the website? There isn't, that information isn't passed in HTTP GET requests.

Aside from asking the user to enter theit time zone, the best you could do would be to lookup their IP address to determine their country, and get the time zone from that. Although that won't always work, and requires a IP -> Country lookup, and as far as I know there's no free databases with that information.


Yeah, I had a feeling that was the case. Option 1 is what I was looking at going for (having the users select their timezone), I was just looking for a cheeky alternative to save some time.

Thanks anyhow Steve.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
as far as I know there's no free databases with that information.

IP-to-country

Quote:
Original post by Sonnenblume
Yeah, I had a feeling that was the case. Option 1 is what I was looking at going for (having the users select their timezone), I was just looking for a cheeky alternative to save some time.

You can check the local time client-side using javascript.

Share this post


Link to post
Share on other sites
You can find out the local time their computer clock is set to with javascript. You can also find out what offset it thinks that has from GMT.

Sadly neither of these things will tell you the user's time zone (you might make an educated guess which is fairly likely to be wrong though)- for that you're just going to have to ask them.

Remember that a time zone is NOT just an offset from GMT.

Mark

Share this post


Link to post
Share on other sites
I'd solve it this way:
Quote:

<?php
if(isset($_GET['timezone'])){
if($_GET['timezone']=="f"){
echo ' Bad Luck.....javascript is not enabled';
}else{
$time_offset=-$_GET['timezone'];
echo 'Timezone is GMT '.$time_offset;
}
}else{
echo'

<script language ="javascript">
< !--
var dt = new Date();
var dtTimezoneOffset = dt.getTimezoneOffset() / 60;
document.location.href ="test.php?timezone="+dtTimezoneOffset;
// -- >
</script>
<a href="test.php?timezone=f">click here if javascript is not enabled</a>
';
}
?>


if javascript is not enabled, the redirect wouldn't workzo, the script receives timezone="f" (or whatever you like)

If you want you can add a meta redirect with 2 secs, if javascript is enabled, it will be faster, if not the script will know that js is not enabled.

You can save the value using SESSION or Cookies.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!