IP功能检测城市
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IP功能检测城市相关的知识,希望对你有一定的参考价值。
This will take an IP and try to find the city.
function detect_city($ip) { $default = 'UNKNOWN'; $ip = '8.8.8.8'; $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; CURLOPT_FOLLOWLOCATION => 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => $curlopt_useragent, CURLOPT_URL => $url, CURLOPT_TIMEOUT => 1, CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'], ); } $city = $regs[1]; } $state = $regs[1]; } if( $city!='' && $state!='' ){ $location = $city . ', ' . $state; return $location; }else{ return $default; } }
以上是关于IP功能检测城市的主要内容,如果未能解决你的问题,请参考以下文章