<?php//Gets the User IP (external IP server can get the user extranet IP native IP address only get 127.0.0.1) function GetIP () {if (!empty ($_server["HTTP_CLIENT_IP"])) { $cip = $_server["Http_client_ip"];} else if (!empty ($_server["Http_x_forwarded_for")) {$cip = $_server["Http_x_forwarded_for"];} else if (!empty ($_server["REMOTE_ADDR")) {$cip = $_server["REMOTE_ADDR"];} else{$cip = ';} Preg_match ("/[\d\.") {7,15}/", $cip, $cips); $cip = isset ($cips [0])? $cips [0]: ' Unknown '; unset ($cips); return $CIP;} $ip =getip ();//According to the Baidu map API to get the user IP geographical latitude and longitude and the city of "HTTP://API.MAP.BAIDU.COM/LOCATION/IP?AK=OMI69HPHPL5LUMTRJFZXN9DF" &ip= $ip &coor=bd09ll "; $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_ Returntransfer, 1); $output = Curl_exec ($ch), if (Curl_errno ($ch)) {echo ' Curl ERROR Code: '. Curl_errno ($ch). ', Reason: '. Curl_error ($ch);} Curl_close ($ch); $info = Json_decode ($output, True), if ($info [' status '] = = "0") {$lotx = $info [' content '] [' point '] [' Y ']; $loty = $info [' content '] [' point '] [' X ']; $citytemp = $info [' content '] [' address_detail '] [' City ']; $keywords = Explode ("City", $citytemp); $city = $keywords [0];} else{$lotx = "34.2597"; $loty = "108.9471"; $city = "Xian";} Var_dump ($lotx);//x coordinates latitude var_dump ($loty);//y coordinates longitude var_dump ($city);//User IP location City
User IP address and Baidu Map API interface to get the user's geographical location (latitude and longitude coordinates, city)