public function ipinfo($ip) { $ipinfo = new ipinfo(); try { if (preg_match('/^[\\w\\.]{1,}.[\\w]{0,4}$/i', $ip)) { $ip = gethostbyname($ip); } if (!$this->isIp($ip)) { throw new \Exception("{$ip} is not an ip", -1); } $httpclient = new \fl\helpers\httpclient(); $jsondata = $httpclient->getData($this->ipserver, null, array('ip' => $ip)); $ipinfo->ip = $ip; if (!$jsondata) { throw new \Exception("network error" . $httpclient->getError(), -1); } $data = json_decode($jsondata, true); if ($data['code'] == 0) { $ipinfo->isp = $data['data']['isp']; $ipinfo->country = $data['data']['country_id']; $ipinfo->area = $data['data']['country'] . ' ' . $data['data']['region'] . ' ' . $data['data']['city'] . ' ' . $data['data']['county']; } else { throw new \Exception("network error, taobao ipsearch error.", -1); } } catch (\Exception $e) { $ipinfo->country = "UNKNOWN"; $ipinfo->area = "UNKNOWN"; $ipinfo->ip = "UNKNOWN"; $ipinfo->isp = "UNKNOWN"; } return $ipinfo; }
function __construct($uri) { $urlinfo = parse_url($uri); if (!isset($urlinfo['scheme'])) { $this->cfgfile = FL_RUNDIR . DIRECTORY_SEPARATOR . 'cfg' . DIRECTORY_SEPARATOR . $uri . '.php'; $this->cfgdata = substr(@file_get_contents($this->cfgfile), strlen($this->diestr)); $this->supportsave = true; } elseif (in_array($urlinfo['scheme'], array('http', 'https'))) { $httpclient = new \fl\helpers\httpclient(); $this->cfgdata = $httpclient->getData($uri); } $this->parse(); }