首页 > 编程知识 正文

查看ip地址,电脑验证国家区代码

时间:2023-05-04 20:25:23 阅读:136325 作者:1705

资料来源: http://www.phpandstuff.com/articles/geo IP-country-lookup-with-PHP

GeoIP PHP? php //计时开始功能时间() { $time=explode ) ',microtime ) ); $usec=(double ) $time[0]; $sec=(double ) $time[1]; 返回$ usec $ sec; } $startTimes=utime (; //includethephpscript//wget-c http://geo lite.maxmind.com/download/geo IP/database/geolitecountry/geo IP.dat //国家代码$ country _ code=geo IP _ country _ code _ by _ addr ($ gi,$_SERVER['REMOTE完美手机] ); echo ' yourcountrycodeis : strong $ country _ code/strong br/'; //国名$ country _ name=geo IP _ country _ name _ by _ addr ($ gi,$_SERVER['REMOTE完美手机' ); echo ' yourcountrynameis : strong $ country _ name/strong br/'; //closethedatabasegeoip _ close ($ gi; //执行结束时间$endTimes=utime (; $runtimes=sprintf('%0.4f”,) $endTimes - $startTimes; echo ' processed in '.$ runtimes.' second.'; 注:本地测试时$_SERVER['REMOTE完美手机和$_SERVER['REMOTE完美手机可能为127.0.0.1,因此输出内容为空。 可以自己带入IP测试

或使用某个网站的彩色绿草/strong

API 1。

1 .返回文本

3358 API.hostip.info/get _ html.PHP? 返回ip=12.215.42.19position=true 2.图像

img src=' http://API.hostip.info/flag.PHP? IP=12.215.42.19 ' alt=' IP address lookup ' API2. (需要API key、免费、谷歌之类的申请) )

3358 API.ipinfodb.com/v3/IP-city/key=your _ API _ keyip=74.125.45.100

3358 API.ipinfodb.com/v3/IP-country/key=your _ API _ keyip=74.125.45.100 parameterrequireddefaultvalue 334 ysemptyapikeyprovidedwithyourfreeaccount.http://www.Sina.com/noclientipipaddress 3358 www.Sina.com/norawraw, XML Jon http://www.Sina.com/noemptyrequiredwhenusingjsoncallback.pleaseusetheapiforyourneeds.youcanhelpuskeepthep

ow on our servers by making sure that : If you only need the country name, avoid using the city precision API.If you track your visitors, avoid querying our API for all your page views (you can store the geolocation in a cookie, see below for an example)
APIPrecisionTimezoneDomains lookups ip-city CityYesYes ip-country CountryNoYes Please use the appropriate API for your needs. You can help us keep the load low on our servers by making sure that : If you only need the country name, avoid using the city precision API.If you track your visitors, avoid querying our API for all your page views (you can store the geolocation in a cookie, see below for an example) <?phpfinal class ip2location_lite{protected $errors = array();protected $service = 'api.ipinfodb.com';protected $version = 'v3';protected $apiKey = '';public function __construct(){}public function __destruct(){}public function setKey($key){if(!empty($key)) $this->apiKey = $key;}public function getError(){return implode("n", $this->errors);}public function getCountry($host){return $this->getResult($host, 'ip-country');}public function getCity($host){return $this->getResult($host, 'ip-city');}private function getResult($host, $name){$ip = @gethostbyname($host);if(preg_match('/^(?:25[0-5]|2[0-4]d|1dd|[1-9]d|d)(?:[.](?:25[0-5]|2[0-4]d|1dd|[1-9]d|d)){3}$/', $ip)){$xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml');try{$response = @new SimpleXMLElement($xml);foreach($response as $field=>$value){$result[(string)$field] = (string)$value;}return $result;}catch(Exception $e){$this->errors[] = $e->getMessage();return;}}$this->errors[] = '"' . $host . '" is not a valid IP address or hostname.';return;}}?>   <?include('ip2locationlite.class.php');//Load the class$ipLite = new ip2location_lite;$ipLite->setKey('<your_api_key>'); //Get errors and locations$locations = $ipLite->getCity($_SERVER['REMOTE完美的手机);$errors = $ipLite->getError(); //Getting the resultecho "<p>n";echo "<strong>First result</strong><br />n";if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { echo $field . ' : ' . $val . "<br />n"; }}echo "</p>n"; //Show errorsecho "<p>n";echo "<strong>Dump of all errors</strong><br />n";if (!empty($errors) && is_array($errors)) { foreach ($errors as $error) { echo var_dump($error) . "<br /><br />n"; }} else { echo "No errors" . "<br />n";}echo "</p>n";   Updated Mar 5 2011

DatabaseUncompressed Size(MB)IP PrecisionData ProvidedFormatDB11.60123.123.123ISO country code, country name CSV BIN DB317.11123.123.123ISO country code, country name, state, city CSV BIN DB521.40123.123.123ISO country code, country name, state, city, latitude, longitude CSV BIN DB922.76123.123.123ISO country code, country name, state, city, latitude, longitude, ZIP codes CSV BIN DB1123.28123.123.123ISO country code, country name, state, city, latitude, longitude, ZIP codes, time zone CSV BIN

key: c9dcc88453e33a9e63ebad8d65f91583e87abd8185dd95f09fbeef6c62264f7d

http://pecl.php.net/package/geoip

http://www.geoiptool.com/

http://www.hostip.info/use.html

http://phpweby.com/software/ip2country

http://www.ipinfodb.com/index.php

转帖注明出处:http://justcoding.iteye.com/blog/986355

php 显示ip所属地 (qq版)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。