Reputation: 11
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
Reputation: 3722
You have a couple options:
Upvotes: 1