Err Posted April 2, 2006 Share Posted April 2, 2006 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 More sharing options...
Err Posted April 2, 2006 Author Share Posted April 2, 2006 Any help would be wonderful. Link to comment Share on other sites More sharing options...
calvin182 Posted April 3, 2006 Share Posted April 3, 2006 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 More sharing options...
vijay Posted April 3, 2006 Share Posted April 3, 2006 Hi Please refer following 2 linkshttp://www.ip2location.com/README-IP-COUNT...-ISP-DOMAIN.htmhttp://www.ip2location.com/free.asp.It will help u out.Regards,Vijay Link to comment Share on other sites More sharing options...
Err Posted May 20, 2006 Author Share Posted May 20, 2006 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 More sharing options...
calvin182 Posted May 20, 2006 Share Posted May 20, 2006 if its not a trouble could u post how u got it working? im just a lil curious... Link to comment Share on other sites More sharing options...
justsomeguy Posted May 20, 2006 Share Posted May 20, 2006 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: OKYou can get more information about it here:http://www.linuxjournal.com/article/7856 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now