Ok so im busy with statistics, now I need to get detailed information from an IP-adress such as region and city. After some research I found out this technique relies on large databases with information on millions of IP-adresses. Can someone either recommend me one ? Preferrable cheap or free but I will listen to all recommendation. If I find your information usefull I wont hesitate to leave you with some green rep. Maybe an alternative ?
Hi Have you tried http://www.maxmind.com/app/ip-location ? They offer free and paid solutions - I believe their paid solutions are more accurate than their free solutions, buts it might be what you are after Brew
Thanks. More are appriciated. (will leave rep when im home, somehow rep button doesnt work on this pc)
here's what i use though you can change it to easily fetch more than the country but that's all i needed so that's all i picked up. function ip2c($lookup_ip) { $ip = $lookup_ip; $context=array('http' => array ('header'=> 'Range: bytes=1024-', ),); $xcontext = stream_context_create($context); $country = file_get_contents("http://api.hostip.info/get_html.php?ip=".$ip."&position=true",false,$xcontext); preg_match("/Country: (.*[^\n]+)/i",$country,$result); return $result[0]; } PHP:
Already managed to get the countries. That not the problem really. What do I need to change on the code to get city and region ? Sorry already found it. Thank you will add to your reputation
replace the regular expression with this and it will return country, city/state, lat, long in an array /country: (.*?)\ncity: (.*?)\nlatitude: (.*?)\nlongitude: (.*?)$/i Code (markup): also note that this will only work in php5 because in php file_get_contents expects only 2 arguments, not 3. so for php4 remove $context=array('http' => array ('header'=> 'Range: bytes=1024-', ),); $xcontext = stream_context_create($context); Code (markup): and then the last argument in the file_get_contents line. "$xcontext" working php4 example: <?php function ip2c($lookup_ip) { $ip = $lookup_ip; $country = file_get_contents("http://api.hostip.info/get_html.php?ip=".$ip."&position=true",false); preg_match("/country: (.*?)\ncity: (.*?)\nlatitude: (.*?)\nlongitude: (.*?)$/i",$country,$result); return $result; } $data = ip2c("24.26.73.230"); echo "Country: ".$data[1]."<br />"; echo "City / State: ".$data[2]."<br />"; echo "Latitude: ".$data[3]."<br />"; echo "Longitude: ".$data[4]."<br />"; ?> PHP: