This article describes the method of obtaining all the information (address, ZIP code, country, latitude, etc.) for the specified (guest) IP in PHP. Share to everyone for your reference. Specifically as follows:
Calling the method is very simple. This also requires a database to support. The Chinese and phonetic characters in the database can coexist.
Nonsense not much to say, look at the code:
<?php
function Getipinfo ($ip, $timeout =15) {
if (!function_exists (' curl_init ') or!function_exists (' Simplexml_load_string ') return false;
$ch = Curl_init ("http://ipinfodb.com/ip_query2.php?ip={$ip}&timezone=true");
$options = Array (
Curlopt_returntransfer => true
);
Curl_setopt_array ($ch, $options);
$res = curl_exec ($ch);
Curl_close ($ch);
if ($xml = simplexml_load_string ($res)) {
$return = array ();
foreach ($xml->location->children () as $key => $item) {
$return [$key] = Strtolower ($item);
}
return $return;
} else {return
false;
}
}
$current _ip_info = getipinfo (' 119.7.8.255 ');
Var_dump ($current _ip_info);
I hope this article will help you with your PHP program design.