<?php
function get_ip_city($ip)
{
$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);
$location = curl_exec($ch);
curl_close($ch);
$location = mb_convert_encoding($location, 'utf-8', 'GB2312');
$location = substr($location, strlen('({') + strpos($location, '({'), (strlen($location) - strpos($location, '})')) * (-1));
$location = str_replace('"', "", str_replace(":", "=", str_replace(",", "&", $location)));
parse_str($location, $ip_location);
return $ip_location['pro'];
}
$ip = $_SERVER['REMOTE_ADDR'];
$time = gmdate("Y-m-d/H:i:s", time() + 8 * 3600);
$gsd = get_ip_city($ip);
$file = "ip.txt";
$fp = fopen("ip.txt", "a");
$txt = "\n" . "$ip" . "\n" . "$gsd" . "----" . "$time" . "\n";
fputs($fp, $txt);
?>