This article mainly introduces PHP based on IP to determine the region name information method, the need for friends can refer to the following
See Code code as follows: <?php header ("content-type:text/html; Charset=utf-8 "); function GetIP () { if (Isset ($_server)) { if (Isset ($_server[http_x_forwarded_for)) { $realip = $_server[http_x_forwarded_for]; } elseif (Isset ($_SERVER[HTTP_CLIENT_IP))) { $realip = $_ server[http_client_ip]; } else { $realip = $_server[remote_addr]; } } else { if (getenv ("HTT P_x_forwarded_for ")) { $realip = getenv (" Http_x_forwarded_for "); } elseif (getenv (" Http_client_ip ")) { $realip = getenv ("Http_client_ip"); } else { $realip = getenv ("remote_addr"); } ret Urn $realip; } $IP = GetIP (); //Use Sina interface based on IP query area information * $res 0 = file_get_contents ("HT tp://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip= $ip "); $res 0 = Json_decode ($res 0); Print_r ($res 0); echo "<br/>"; */ //using Taobao interface based on IP query area information $res 1 =File_get_contents ("http://ip.taobao.com/service/getIpInfo.php?ip= $ip"); $res 1 = json_decode ($res 1); /* Print_r ($res 1); */ How to read the data, look below. The code is as follows: $array = Get_object_vars ($res 1);//assignment to array foreach ($array as $value) { echo $value->region. " <br/> "; echo $value->city." <br/> "; echo $value->ip." <br/> "; } ?> /or access to echo $res 1->data->city; with Object data