views:

5929

answers:

5

Hi,

I want to get time zone through IP Address in PHP. Actually i have an application which will run at the client machine. I have IP address of client machine. But not able to get the time zone for each client machine.

Please reply me.

Thanks Devesh M

+4  A: 

If you're running it on the local machine, you can check the configured timezone.
http://www.php.net/manual/en/function.date-default-timezone-get.php

There are a lot better and more reliable methods then trying to guess timezone using GeoIP. If you're feeling lucky, try: http://www.php.net/manual/en/book.geoip.php

$region = geoip_region_by_name('www.example.com');
$tz = geoip_time_zone_by_country_and_region($region['country_code'],
                                            $region['region']);
vartec
The application is running on the local machine, but i want to get time zone through IP on the server side, not on local machine.
Devesh M
I would love to have a local copy the GeoIP timezone data.
Jacco
+3  A: 

There's no absolutely certain way to get the client's timezone, but if you have the client submit the date and time from their machine, you can compute it based on what the time it is relative to GMT. So, if it's 7:00pm on their machine and it's 12:00am GMT, then you can determine they are -5 from GMT or (EST/DST)

altCognito
Timezones are quite difficult, as most internationalization problems are. If you know their current time AND if they are on daylight saving or not, then you can determine their timezone. Figuring out the daylight saying is however, very difficult (again)
Jacco
+5  A: 

IP address can't even be relied upon to map to a country; you're treading on thin ice if you also want to get timezone. You're better off to have the client send you the time zone, perhaps in a header.

See Tor: anonymity online for yet another reason to stop using IP addresses for things they were not designed for.

John Saunders
A: 

If what you need to know is the timezone of users browsing your webpage, then you can use some service like IP2LOCATION to guess the timezone. Keep in mind though, as altCognito said, this is not a 100% accurate way of telling client's timezone. There are some problems accuracy problems with this approach.

Pablo Santa Cruz
A: 

Hi, I want to know how to change timezone region code.

Khin Thu Thu Mon