studgate Posted February 23, 2011 Share Posted February 23, 2011 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 ); } Quote Link to comment https://forums.phpfreaks.com/topic/228553-current-city-from-ip-address/ Share on other sites More sharing options...
Rifts Posted February 23, 2011 Share Posted February 23, 2011 http://sourceforge.net/projects/geoip/ Quote Link to comment https://forums.phpfreaks.com/topic/228553-current-city-from-ip-address/#findComment-1178500 Share on other sites More sharing options...
optikalefx Posted February 23, 2011 Share Posted February 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/228553-current-city-from-ip-address/#findComment-1178505 Share on other sites More sharing options...
studgate Posted February 23, 2011 Author Share Posted February 23, 2011 i am gonna try these options guys but is there a way for me to get the metropolitain area for that ip address, I get the current city where the ip address resides but get me Boston, instead of Foxboro. Quote Link to comment https://forums.phpfreaks.com/topic/228553-current-city-from-ip-address/#findComment-1178643 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.