Jump to content

Current City from IP Address


studgate

Recommended Posts

ok guys, i know you guys are awesome and I always get the help and I need some help in

figuring the current city and the metropolitan area from an ip address. For example, if I am

in Harlem, NY, I need to get the Harlem and New York. I have a code that is partially working

but not accurate enough, please guys help, something like groupon will do.

 

function currentCity () {
( ( (float)phpversion() < 5.3 ) ) ? die ( 'There is something wrong!' ) : '';

$site = file_get_contents( "http://www.google.com/search?q=VBXMCBVFKJSHDKHDKF" );

$getLocationViaGoogle = function ( $html ){
	$regex = "#<\w+\s\w+=\"tbos\">([^<]{3,})<\/\w+>#i";
	preg_match_all( $regex, $html, $matches );
	return $matches[1][0];
};

print $getLocationViaGoogle( $site );
}

Link to comment
https://forums.phpfreaks.com/topic/228553-current-city-from-ip-address/
Share on other sites

i hate non helpful links with no text.

 

PHP has built in functions for GEOIP.  You need to install a quick PECL extension for it work, but its fast as long as you have SSH access to your server.

 

 

then once its installed you can use

 

geoip_record_by_name

 

to get the city info

more info here

http://www.php.net/manual/en/function.geoip-record-by-name.php

install instructions are there as well.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.