Example code for PHP to determine locale name information based on IP

Source: Internet
Author: User
Tags locale

  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
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.