Jump to content

Finding the accurate zip code based on IP Address


junejune

Recommended Posts

Hi,

 

I am building an application in my page where I need to add geolocation functionality and I need the visitors zip code in return, like say within 100miles. I have some sample source code but returning only Country, States and City.
 
Could anyone please help? Any input is greatly appreciated.
 
 

Use a script to calculate the geolocation (ipgetinfo is helpful), something among the lines of <?php function geo() { $ip = $_SERVER['REMOTE_ADDR']; $url = 'http://www.ipgetinfo.com/index.php?ip='.$ip.''; $gc = fopen($url, "r"); $doc = new DOMDocument(); $fc = stream_get_contents($gc); $doc->load($gc); $doc->getElementsByClassName('...'); ... } ?>.

The script isn't completed yet, as I cannot get on a PC anytime soon, I have to cancel the script early, write a script that calculates the zip out of the geolocation data ipgetinfo provides. Hope this helped.

Not accurately, no. You might get the country, and the general vicinity (city) correct most of the time. But, the ZIP-code: No chance to get the correct one with any degree of accuracy.

 

Contrary to Hollywood, an IP-address isn't tied to a geographical location, but to businesses. Internet Service Providers. Whom then, in turn, assign these to their customers based upon various internal rules. For the big national ISPs, this might mean that a single IP-address could be used anywhere in the whole country, depending upon who requested an IP-address first when that particular IP-address was available. Smaller, or more sectioned up ISPs could give you a smaller geographical area, possibly down to city-level. Though, not much more than that, and a city has multiple ZIP-codes after all.

That's not even considering the vast areas with a minimal population, such as the countryside.

 

The only way to get the accurate ZIP-code for any given IP-address, is to actually look it up in the ISPs registers. Which means comparing their DHCP logs with their customer registers, something which would be illegal without a court order.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.