IP to location + local time? - php

Currently I've been using http://www.geoiptool.com/ but I can't get the local time. I don't know what to do to get the local time.
Can someone help me out, to display location + local time? I have a mail app and I try to display IP in location + local time.

Well, this is not real answer to your question but can help you to properly understand how inaccurate this method is.
Please, read this answer as a side note.
Yes, it's OK to offer or set location/time for your users. But you should provide country/time selector for them also. Some of IP's can not be resolved properly (anonymous proxy, borrowed IPs from other countries (my case), continental IPs (like group "Europe", "Asia", etc), etc.
My case shows how this approach may be wrong.
When I've tried ipLocator from geobytes.com I've got this:
My IP address has been resolved to:
Location: Romania
Time offset: +0200 (at the moment DST is active so it's +0300)
Real problem is that my location is not Romania, and my time offset is +0100/+0200.
Look this picture:
Red arrow shows my real location. Info in black box shows correct values for my real location. Well, wrong location is not such a big problem for users, but wrong local time is very annoying thing.
Yes, I know, that's not what you're looking for. But you should not fix users location and/or local time because it can be wrong approach. IPv4 address is certainly not something accurate to get real info about user.
Also, I found that ipLocator doesn't follow DST rules and using that time offset (image #1) will show wrong local time during Summer (for countries/regions/provinces which consider DST).

Geobytes will give you the offset:
http://www.geobytes.com/IpLocator.htm?GetLocation&IpAddress=64.34.119.12
Or in an XML format (you might need to view source to see it):
http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=64.34.119.12
This will give you the offset, just add/subtract the offset to GMT/UTC.

Related

How to Get 2 Digit Country Code by Using php

Hello Friends I was Developing an website which i only want to be viewed by Indian (People of india) , and I Want to Get The Two Digit Country Code for that using php. I browsed to http://php.net and tried using geoip_country_code_by_name , geoip_country_code3_by_name and geoip_country_name_by_name but None of Function worked , I have tried on my Existing XAMPP Installation and W3schools PHP runner but it says function not exists and i also have checked to PHP version. What Should i Do. I also Have tried methods form here and after Google(ing) whole day i finally came to ask here .Feel Free to Suggest Edit or Close this Question
Based on some research, the best way seems to be by IP. This link will help you if you go this way.
https://stackoverflow.com/a/13600004/13604954
But some VPN can easily change is on IP.
ref. https://nordvpn.com/blog/vpn-ip-location-changer/
So good luck! 😉
The easiest way will be to asking the user is country and if not what you want, just show another page.

How to specify location on Bing in the URL

I am doing some minor cURL work and, unlike Google, Bing defaults the search results to the location of the server. I am trying to find a parameter to set that allows me to specify location, for example UK/US, but I haven't had much luck.
Does anyone know or have a link to an article explaining this?
Thanks in advance!
I actually found it, after searching for 30 minutes and posting this I stumbled upon it. You can set it using the something like "setmkt=fr-fr"
Where the first is the language, the second the location. I can't be sure what it will accept but I figure playing with that will get the desired results.
Bing! probably does it based on the IP of the connecting client.
Since you can't change that (other than connecting via a proxy, which is a whole different story), you cannot manually set the location for your search results (unless of course, Bing! has an option or an API which allows it).
I believe you could use the Location Data parameter:
http://msdn.microsoft.com/en-us/library/ff701726.aspx
You can specify countryRegion to limit the results to a certain country:
A string specifying the country or region name of an address.
Example: United States

Identifying user's location based not on IP

I know how can I determine user's location using IP number. However, I'm wondering if there is some more precise technique. I've seen that some applications, eg. Google MAPS, are asking a user for permission to get his location. Is there some kind of such API? Am I missing something?
Thanks a lot!
The only generally available, more exact method known to me is the HTML 5 geolocation API. That API can sometimes fetch a more exact location by scanning nearby wireless networks and their IDs, or querying a GPS device attached to the computer (or as #Pascal says, a GPS device built into a mobile device like an iPhone).
This however works only if the computer has the right hardware, and requires explicit consent from the user.
For user-consent-free, server-side geolocation, the IP-based method is still the best you can do.
See this question for a great rundown on how it works: About Geolocation in HTML 5
Some devices (typically, smartphones) have a GPS -- which means quite precise location -- or can use wifi / cell-towers / ...
You cannot get that location on the server (it's not sent by the browser), but you could get it from Javascript (and, then, send it to the server, using some Ajax).
For some documentation, you can take a look at :
W3C Geolocation API
And Using geolocation (which applies at least to Firefox >= 3.5)
Seems to be problems with GeoLocation in HTML5 http://ipgeo5.com/
Yesterday I was in Montreal and worked perfectly pinpointing my current location to the nearest 30 feet(estimate). Running Windows XP, Chrome 14.0.835.
Today, I am at my mom's house in a small town in Ontario, Canada and getting this error.
Your Current Location
We have estimated you are located at
Notice: Undefined property: stdClass::$AdministrativeArea in /var/www/ipgeo5.com/pages/city.php on line 29
Notice: Trying to get property of non-object in /var/www/ipgeo5.com/pages/city.php on line 29
, , Canada by using HTML 5 Geolocation technique.
Your location:
Notice: Undefined property: stdClass::$AdministrativeArea in /var/www/ipgeo5.com/pages/city.php on line 29
Notice: Trying to get property of non-object in /var/www/ipgeo5.com/pages/city.php on line 29
, , Canada
So I guess this is not 100% effective !
So needs to have Plan B using IP2Location database to identify location.
Thanks !
Michel, Montreal, Canada
That would be the geolocation API.
See the Geolocation API and the matching section of Dive into HTML 5

Information stored in a cookie file

Thanks for you help in advance.
I am trying to figure out the structure of the cookie file, more specifically i want to be able to determine the expiry time. From the cookies i have created they all appear to be in a standard format. Name, Value, website,followed by 5 numbers and a star. See example below.
name
value
www.website.co.uk/
1536
3041141504
30135951
1632526096
30135949
*
Obviously the expiry time is one of the numbers, the question is which one. From experiments I have determined that the first and fifth number don't seem to change. In a case where i generated three cookies at the same time with a 1000 second time difference i noticed that the fourth number appeared to increase by 2000 suggesting that this has a connection with the expiry time.
Can anyone confirm if i am heading in the right direction? And does any one know how i convert this to a human time and date(preferably in php but any language would give me a starting point)
thanks
Jason
I am trying to figure out the structure of the cookie file...
There isn't one. It's entirely up to the browser where and how to store cookies on the client computer. You can certainly solve this for popular browsers, but it won't be the same solution for all of them. Some store cookies in flat files; others store them in individual files (per cookie, or per site), others as SQLite databases...
I have figure out the answer. Thanks to everyone who responded.
The format of the the cookie in ie8 is:
name
value
website
flags-not entirely sure what this is
expiration time (low)
expiration time (high)
creation time (low)
creation time (high)
To convert these numbers into actual times you can use the following formula:
time = 1*10-7*(high*2^32+low)-1164447360
thanks again
Jason

Resolve geographical/GPS coordinates to current local time

I am trying to resolve a location's coordinates (latitude, longitude), to an accurate current local time.
For example, let's say I have a list of locations on a website. When I look at a specific location I will always know its latitude/longitude (it could be anywhere in the world). I would like to display the current time at that location.
I can write something from scratch by myself, but I was wondering if there are any libraries/plugins that would allow me to do this faster.
Thanks,
See Timezone lookup from latitude longitude

Categories