资料来源: 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)
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版)