发现问题? 你可以框选文本并按 Ctrl+Enter反馈管理员处理,感谢!
1.IP-API接口归属地:接口速度真的很拉胯,导致数据包丢失30%~35%。故弃之...实属无奈啊
弃用之后obaby提供了自用接口给我,因为某些顾虑问题没有启用,但还是要感谢一下的!也由此产生了自建的想法...后来和老朋友聊起属地问题,简直不要太意外!特别鸣谢Reishi提供 IP2Location 数据库,所以有了现在的自建历程。同时加载速度问题也迎刃而解
2.IP2Location IP 地理位置 PHP 模块安装
安装运行:
composer require ip2location/ip2location-php
引用 IP2Location 类文件
require 'vendor/autoload.php';
示例代码 详见官方文档
require 'vendor/autoload.php';
/*
Cache whole database into system memory and share among other scripts & websites
WARNING: Please make sure your system have sufficient RAM to enable this feature
*/
// $db = new \IP2Location\Database('./data/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN-SAMPLE.BIN', \IP2Location\Database::SHARED_MEMORY);
/*
Cache the database into memory to accelerate lookup speed
WARNING: Please make sure your system have sufficient RAM to enable this feature
*/
// $db = new \IP2Location\Database('./data/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN-SAMPLE.BIN', \IP2Location\Database::MEMORY_CACHE);
/*
Default file I/O lookup
*/
$db = new \IP2Location\Database('./data/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN-SAMPLE.BIN', \IP2Location\Database::FILE_IO);
$records = $db->lookup('8.8.8.8', \IP2Location\Database::ALL);
echo '<pre>';
echo 'IP Number : ' . $records['ipNumber'] . "\n";
echo 'IP Version : ' . $records['ipVersion'] . "\n";
echo 'IP Address : ' . $records['ipAddress'] . "\n";
echo 'Country Code : ' . $records['countryCode'] . "\n";
echo 'Country Name : ' . $records['countryName'] . "\n";
echo 'Region Name : ' . $records['regionName'] . "\n";
echo 'City Name : ' . $records['cityName'] . "\n";
echo 'Latitude : ' . $records['latitude'] . "\n";
echo 'Longitude : ' . $records['longitude'] . "\n";
echo 'Area Code : ' . $records['areaCode'] . "\n";
echo 'IDD Code : ' . $records['iddCode'] . "\n";
echo 'Weather Station Code : ' . $records['weatherStationCode'] . "\n";
echo 'Weather Station Name : ' . $records['weatherStationName'] . "\n";
echo 'MCC : ' . $records['mcc'] . "\n";
echo 'MNC : ' . $records['mnc'] . "\n";
echo 'Mobile Carrier : ' . $records['mobileCarrierName'] . "\n";
echo 'Usage Type : ' . $records['usageType'] . "\n";
echo 'Elevation : ' . $records['elevation'] . "\n";
echo 'Net Speed : ' . $records['netSpeed'] . "\n";
echo 'Time Zone : ' . $records['timeZone'] . "\n";
echo 'ZIP Code : ' . $records['zipCode'] . "\n";
echo 'Domain Name : ' . $records['domainName'] . "\n";
echo 'ISP Name : ' . $records['isp'] . "\n";
echo 'Address Type : ' . $records['addressType'] . "\n";
echo 'Category : ' . $records['category'] . "\n";
echo 'District : ' . $records['district'] . "\n";
echo 'ASN : ' . $records['asn'] . "\n";
echo 'AS : ' . $records['as'] . "\n";
echo '</pre>';
// Web Service
$ws = new \IP2Location\WebService('demo', 'WS25', false);
$records = $ws->lookup('8.8.8.8', [
'continent', 'country', 'region', 'city', 'geotargeting', 'country_groupings', 'time_zone_info',
], 'en');
echo '<pre>';
print_r($records);
echo 'Credit Remaining: ' . $ws->getCredit() . "\n";
echo '</pre>';
?>
游客可见(属地)
游客不可见(属地)
更新:回复评论时加载bug修复,查看日志是库路径错误!真不应该,太马虎了!
Fatal error: Uncaught Error: Failed opening required '/ip/vendor/autoload.php' (include_path='/classes/htmlpurifier/standalone:.:') in /cache/system/plugins/afeb67169ea20565441b28a55909ddca.php:269
Stack trace:
#0 /cache/system/plugins/afeb67169ea20565441b28a55909ddca.php(285): myFunction()
#1 /cache/system/plugins/afeb67169ea20565441b28a55909ddca.php(117): _Comments->compile_comment()
#2 /cache/system/plugins/afeb67169ea20565441b28a55909ddca.php(1109): _Comments->compile_comments()
#3 /cache/system/plugins/8c5cee75dd799d1f644902f7b4a1c564.php(86): _Comments->build_comments()
#4 /ajax/controller.php(195): include_once('...')
#5 {main}
thrown in /cache/system/plugins/afeb67169ea20565441b28a55909ddca.php on line 269