Hi
pleas i need your helps:
i want a php code that worked with GeoIP and when someone want to visit my website page like “getloc.php” the result show like that site:
Thanks for help
Hi
pleas i need your helps:
i want a php code that worked with GeoIP and when someone want to visit my website page like “getloc.php” the result show like that site:
Thanks for help
Here is code for that:
http://roshanbh.com.np/2008/07/getting-country-city-name-from-ip-address-in-php.html
Nice
but its have a problem and with all IP its just show UNITED STATES !!!
Hmmm, yes, it does not work very well. Seems that site has their own database and do not update it much.
I looked around the web and found other code, but, most did not work well and could not give me my location.
There was a code that is supposed to pull the LAT/LON from National Geographic’s website so you can get the
location that way. Not sure if it works, no time to test today. But, give it a try…
[php]
function getLocationCaidaNetGeo($ip)
{
$NetGeoURL = “http://netgeo.caida.org/perl/netgeo.cgi?target=”.$ip;
if($NetGeoFP = fopen($NetGeoURL,r))
{
ob_start();
fpassthru($NetGeoFP);
$NetGeoHTML = ob_get_contents();
ob_end_clean();
fclose($NetGeoFP);
}
preg_match ("/LAT:(.)/i", $NetGeoHTML, $temp) or die(“Could not find element LAT”);
$location[0] = $temp[1];
preg_match ("/LONG:(.)/i", $NetGeoHTML, $temp) or die(“Could not find element LONG”);
$location[1] = $temp[1];
return $location;
}
[/php]
Then, you can convert that to the city/state…
Also, I found this link for you:
http://pecl.php.net/package/geoip
It is supposed to do what you want. The company to created it is now selling it as a service. I did go to their site and check my IP (They allow 25 free) and it was accurate down to the city and server’s city! Not sure if this will help!
It seems there are several other ways to do this. You can do a “WHOIS” function on many sites and get the location that way. Seems that a lot of them just give out the server’s location, though. Good luck!
(Please post back if you solve this as we all want to know!)
Thank you for reply and help :-*
But how can use this function ?! its just a function !!
Well, you use this line:
$ip=@$REMOTE_ADDR;
To capture the user’s IP and call the function. This gives you something to feed the function.
That returns the LAT/LON which tells you where they are.
Then, you can use the GEOcode to locate the place. It basically finds the closest location to the LAT/LON.
http://geocoder.ca/
I have did not test all of this, but, I know that should work for you…