junejune Posted June 11, 2013 Share Posted June 11, 2013 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. Quote Link to comment Share on other sites More sharing options...
Irate Posted June 11, 2013 Share Posted June 11, 2013 (edited) 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. Edited June 11, 2013 by Irate Quote Link to comment Share on other sites More sharing options...
Christian F. Posted June 11, 2013 Share Posted June 11, 2013 (edited) 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. Edited June 11, 2013 by Christian F. Quote Link to comment Share on other sites More sharing options...
DaveyK Posted June 11, 2013 Share Posted June 11, 2013 Moderns browsers support geolocation right? I imagine there is a JS solution for that? A browser will request the users location and the user can accept or deny. Quote Link to comment Share on other sites More sharing options...
junejune Posted June 17, 2013 Author Share Posted June 17, 2013 Hi all, thanks for the replies, I am trying with another easy solution after reading all of the clues. Will be back once I solve my problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.