function getIpAddress($ip = ''){ // ip territory (from Pacific Computer Network)
if(empty($ip)){
$ip = $_REQUEST['ip'];
if(empty($ip)) die('Please transmit the ip address'); //Return data according to the actual calling method
}
$ch = curl_init();
$url = 'https://whois.pconline.com.cn/ipJson.jsp?ip=' . $ip;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
curl_close($ch);
$data = mb_convert_encoding($data, 'utf-8', 'GB2312'); // Convert encoding
//Intercept the string in {}
$data = substr($data, strlen('({') + strpos($data, '({'), (strlen($data) - strpos($data, '})')) * (-1));
// Replace the ‘,’ in the intercepted string $data with ‘&’ and replace the ‘:’ in the string with ‘=’
$data = str_replace('"', "", str_replace(":", "=", str_replace(",", "&", $data)));
parse_str($data, $addressInfo); // Convert string to array format
//return $addressInfo['addr']; // Return the IP address, such as: Chengdu, Sichuan Telecom ADS
return $addressInfo['pro']; // Return the IP address, such as: Sichuan Province
//return $addressInfo['city']; // Return the IP address, such as: Chengdu City
}
The above code comes from the 20220705 network. We need to add the code to the DESTOON custom function php file. The file location is api/extend.func.php
Front-end retrieval method
No matter where it is, first you need to get the tag of the native IP and just add it outside the tag, such as:
{getIpAddress($ip)}
Note: In different places $ip There are different ways of writing it, such as: $t[ip] is used in the loop, and the registered IP used in the company store is $C OM[regip], the member login IP is $COM[loginip]
Display the result graph (we only display the province here, you can display the city or province + city), pay attention to the annotations of the php function.
