user1987802
user1987802

Reputation: 11

Using GeoIP only for US locations not 100% accurate

I have a module built to use the GeoIP Database. Im using it to get the location of the user visiting the website and we can provide the current weather on their city (only USA) pulled from YQL weather. I found this https://stackoverflow.com/questions/12365078/best-way-to-get-location-weather-details-accurately which reads is not going to be very accurate without letting the user enter their location.

So far it has been 90% succesfully displaying correct locations, sometimes we have to renew the DHCP lease to get the correct location... but my client still cannot pull the right city in their office. I don't really know much about their network connection, but I wonder if it is being forwarded, etc...

Here is how I am obtaining the user's IP on the module:

function getIpAddresses() {
   $ipAddresses = array();
   if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {

  $ipAddresses['proxy'] = isset($_SERVER["HTTP_CLIENT_IP"]) ? $_SERVER["HTTP_CLIENT_IP"] : $_SERVER["REMOTE_ADDR"];
  $ipAddresses['user'] = $_SERVER["HTTP_X_FORWARDED_FOR"];

  } else {
  $ipAddresses['user'] = isset($_SERVER["HTTP_CLIENT_IP"]) ? $_SERVER["HTTP_CLIENT_IP"] : $_SERVER["REMOTE_ADDR"];
  }
   return $ipAddresses;
  }

Is there a better way to get the IP / improve the accuracy without requesting the user's entry of their location? Thanks!

Upvotes: 1

Views: 380

Answers (1)

preinheimer
preinheimer

Reputation: 3722

You have a couple options:

  • Look for a better GeoIP data provider. There are several free data providers, in my experience they're pretty good at things like country level, as you get more granular you need to look at commercial solutions.
  • Record which IP they're at, even if they're renewing their IP they're probably sticking around in a particular sub-net. Hard code that sub-net to the correct location.
  • Incorporate a javascript location API, and send that data to the server. If the client computer is a laptop, it may provide better location information than simple GeoIP.

Upvotes: 1

Related Questions