Mengembalikan "Kota, Negara Bagian" jika ditemukan sebaliknya set default di atas.
function detect_city($ip) ( $default = 'UNKNOWN'; if (!is_string($ip) || strlen($ip) 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => $curlopt_useragent, CURLOPT_URL => $url, CURLOPT_TIMEOUT => 1, CURLOPT_REFERER => 'http://' . $_SERVER('HTTP_HOST'), ); curl_setopt_array($ch, $curl_opt); $content = curl_exec($ch); if (!is_null($curl_info)) ( $curl_info = curl_getinfo($ch); ) curl_close($ch); if ( preg_match('(
City : ((^<)*)
)i', $content, $regs) ) ( $city = $regs(1); ) if ( preg_match('(
State/Province : ((^<)*)
)i', $content, $regs) ) ( $state = $regs(1); ) if( $city!='' && $state!='' )( $location = $city . ', ' . $state; return $location; )else( return $default; ) )