当前位置:网站首页>utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
2022-07-03 16:35:00 【Leaf drop traceless 123】
stay WEB Application , according to IP Address location and logging are also very common requirements , stay ThinkPHP You can easily achieve IP Address acquisition and location
It can be downloaded from the official website IP Locate the extended class library , Or the extension class is already included in the download extension package . If it is an uploaded class library downloaded separately , Take the decompressed IpLocation.class.php Put in ThinkPHP/Extend/Library/ORG/Net/( If not, please manually create ) Below directory .
One 、 obtain IP Address
If you only need to get user access IP Address , Then directly use the built-in get_client_ip Function , The function is ThinkPHP Standard mode built-in method , You can use it directly , Than PHP Built in system variables $_SERVER['HTTP_CLIENT_IP'] Better compatibility , usage :$ip = get_client_ip();
get_client_ip Support IP Address detection and legitimacy verification , The return value is obtained IP Address , If I get it IP Illegal address , Will return 0.0.0.0.
if necessary , You can also return IPV4 Address number , for example :$ip = get_client_ip(1);
The result returned may be similar to :2130706433
It can be used for address range and comparison .
Two 、IP Address location
Just get IP Address can not fully meet the needs of applications , It can only be recorded for future log analysis ,IP The address location function allows you to get the user's area . To use IP Positioning function , Except for the need to IpLocation Beyond the extended class library , It also needs to be IP Address library file , because ThinkPHP By default UTF8 code , So it's better to UTF8 Format IP Address library file , If it is pure gbk Coded IP Address library file , You need to encode and convert the obtained results ( As we'll see )
Unzipped address library file UTFWry.dat Put in IpLocation Under the directory where the extension class library is located .
Usage method :import('ORG.Net.IpLocation');// Import IpLocation class
$Ip = new IpLocation(); // Instantiate the class
$location = $Ip->getlocation('218.79.93.194'); // Get a IP The location of the address
Back to location Variable is an array , Include :$location['ip'] // IP Address
$location['beginip'] // user IP The starting address of the range
$location['endip'] // user IP The end address of the range
$location['country'] // Country or region
$location['area'] // Area
Usually , We want to get IP Positioning words , Just take country and area Information :$info = $location['country'].$location['area'];
If you use it IP The address library file is not UTFWry.dat( Pay attention to Linux The case of the following file names also needs to be consistent ) Words , We need to instantiate IpLocation Class, pass in the address library file name , for example :$Ip = new IpLocation('MyIpWry.dat'); // Pass in IP Address library file name
If your IP Address library is GBK Code words , You need to encode and convert the returned results . for example :$info = iconv('gbk','utf-8',$location['country'].$location['area']);
If the getlocation Method without passing any parameters , The system will automatically call the above get_client_ip Function to get the current IP Address :$location = $Ip->getlocation();
You can also support the incoming domain name to automatically obtain ip Address import('ORG.Net.IpLocation');// Import IpLocation class
$Ip = new IpLocation(); // Instantiate the class
$area = $Ip->getlocation('www.thinkphp.cn'); // Get the location of the domain name server
dump($area);
Run result output :

If you use innocence IP Address base , Or you often need to change different address libraries , For convenience IP Locate the query , You can also package a function separately to obtain location information .
The above is the whole content of this paper , I hope it will be helpful for your study , For more information, please pay attention to PHP Chinese net !
Related to recommend :
Related resources :UTFWry.dat(ThinkPHPIP Locate the address library file )_lsDefaultItemFilter- Other ...
边栏推荐
- Remote file contains actual operation
- 关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
- 面试之 top k问题
- 疫情常态化大背景下,关于远程办公的思考|社区征文
- Everyone in remote office works together to realize cooperative editing of materials and development of documents | community essay solicitation
- Leetcode binary search tree
- (补)双指针专题
- 什么是质押池,如何进行质押呢?
- Alibaba P8 painstakingly sorted it out. Summary of APP UI automated testing ideas. Check it out
- Mysql 将逗号隔开的属性字段数据由列转行
猜你喜欢

Colab works with Google cloud disk

探索Cassandra的去中心化分布式架构

2022爱分析· 国央企数字化厂商全景报告

2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises

NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)

深入理解 SQL 中的 Grouping Sets 语句

Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs

近视:摘镜or配镜?这些问题必须先了解清楚

面试官:JVM如何分配和回收堆外内存

There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
随机推荐
Aike AI frontier promotion (7.3)
1287. Elements that appear more than 25% in an ordered array
面试官:JVM如何分配和回收堆外内存
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
PHP CI (CodeIgniter) log level setting
【剑指 Offer】58 - I. 翻转单词顺序
Svn usage specification
Multithread 02 thread join
Add color to the interface automation test framework and realize the enterprise wechat test report
Mb10m-asemi rectifier bridge mb10m
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
(补)双指针专题
Initial test of scikit learn Library
Golang 装饰器模式以及在NSQ中的使用
Mysql 单表字段重复数据取最新一条sql语句
Threejs Part 2: vertex concept, geometry structure
14 topics for performance interviews between superiors and subordinates (4)
[statement] about searching sogk1997 and finding many web crawler results