views:

31

answers:

3

I'm hosting my site in US and my site lists events based on time and holidays and birthdays based on dates..

I'm using php and mysql

when someone visits my site from india the date that will be shown on the site will be a day lesser..

How can i get the change the date and time based upon the visitor's country?

A: 
  1. Get the IP of the visitor by using this:
    $visitorIP = $_SERVER['REMOTE_ADDR'];

  2. Map it to country / city. There are many IP to country database available. I prefer MaxMind GeoIP Country Database and MaxMind GeoIP City Database.

  3. Convert the timezone to that country / city.

shamittomar
I think countries can have > 1 timezone.
alex
@Alex, yes but you can also get CITY from IP and map timezone to that city.
shamittomar
@shamitomar. The timezone cities are the major city in the timezone. Often the Capital of the country. Canada has one timezone city per province. The USA has at least one timezone per state, as some states have multiple timezones. Asking the user which timezone for their country (if there are more than one) is a good way to get it correct. The are additional aliases in the database for less reliable timezone names such as EST, CST, etc.
BillThor
+1  A: 

You can get their timezone offset with JavaScript.

alex
A: 

@Ishmaeel said:

The most popular (==standard?) way of determining the time zone I've seen around is simply asking the user ximself. If your website requires subscription, this could be saved in the users' profile data. For anon users, the dates could be displayed as UTC or GMT or some such.

I'm not trying to be a smart-alec. It's just that sometimes some problems have finer solutions outside of any programming context.

http://stackoverflow.com/questions/13/how-can-i-determine-a-web-users-time-zone/797#797

vfn