Jump to content

IP Location


Err

Recommended Posts

Hello. I'm building a page with php in it, and I need the php that displays the IP Location of the user viewing my page (by that I mean the country of the viewer) ... I've done some google searches but there are only "programs" that I have to download or it isn't php itself. I just want a simple php script that displays the users IP location on the same page -- without all that fuss. Is it even possible with a few lines of php script? I'm still new to php so I don't know much about it. If someone knows the php script for this can you stop by and at least post it please?I got this close:

<?php echo ($_SERVER["HTTP_CLIENT_IP"]);  $country = GetCountry($_SERVER["HTTP_CLIENT_IP"]); ?>

But, it doesn't work I get this error:fatal error: Call to undefined function: getcountry() in /home/www/mysite/index.php on line 65.:)

Link to comment
Share on other sites

well I personally don't know how to do this simply, or at all for that matter, but here is a script that you esentially does what you want.http://www.scriptsez.net/index.php?action=...l&id=1087484351it's a .zip file with a php file, a dat file, and a readme. so, it's not as small as you'd like it, but it's the smallest I could find. i hope this helps you!

Link to comment
Share on other sites

  • 1 month later...

Hmm... I thought I posted a response in this thread.:S Weird.Well, anyways. Thanks for the input folks. I got it working.

Link to comment
Share on other sites

Here's a PHP function that queries the Caida Netgeo database:

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;}

The response from the netgeo server contains a lot of informaiton, and looks like this:

$ http://netgeo.caida.org/perl/netgeo.cgi?target=192.168.0.1 VERSION=1.0TARGET: 192.168.0.1NAME: IANA-CBLK1NUMBER: 192.168.0.0 - 192.168.255.255CITY: MARINA DEL REYSTATE: CALIFORNIACOUNTRY: USLAT: 33.98LONG: -118.45LAT_LONG_GRAN: CityLAST_UPDATED: 16-May-2001NIC: ARINLOOKUP_TYPE: Block AllocationRATING: DOMAIN_GUESS: iana.orgSTATUS: OK
You can get more information about it here:http://www.linuxjournal.com/article/7856
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...