当前位置:网站首页>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 ...
边栏推荐
- 中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
- The mixlab editing team is recruiting teammates~~
- QT串口ui设计和解决显示中文乱码
- Data driving of appium framework for mobile terminal automated testing
- [sword finger offer] 58 - I. flip the word order
- NSQ source code installation and operation process
- LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
- "The NTP socket is in use, exiting" appears when ntpdate synchronizes the time
- (补)双指针专题
- SVN使用规范
猜你喜欢

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
![[web security] - [SQL injection] - error detection injection](/img/18/5c511871dab0e5c684b6b4c081c061.jpg)
[web security] - [SQL injection] - error detection injection

8个酷炫可视化图表,快速写出老板爱看的可视化分析报告

Visual SLAM algorithms: a survey from 2010 to 2016

Multithread 02 thread join

One article takes you to understand machine learning

There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them

Netease UI automation test exploration: airtest+poco

Visual SLAM algorithms: a survey from 2010 to 2016

Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
随机推荐
【剑指 Offer 】57 - II. 和为s的连续正数序列
Is it safe to open a stock account by mobile registration? Does it need money to open an account
Colab works with Google cloud disk
TCP congestion control details | 3 design space
The word backspace key cannot delete the selected text, so you can only press Delete
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
Stm32f103c8t6 firmware library lighting
程序猿如何快速成长
Myopia: take off or match glasses? These problems must be understood clearly first
手机注册股票开户安全吗 开户需要钱吗
Golang 匿名函数使用
记一次jar包冲突解决过程
Mixlab编辑团队招募队友啦~~
Unreal_DataTable 实现Id自增与设置RowName
Record windows10 installation tensorflow-gpu2.4.0
14 topics for performance interviews between superiors and subordinates (4)
Unity项目优化案例一
TCP擁塞控制詳解 | 3. 設計空間
Learn from me about the enterprise flutter project: simplified framework demo reference
Aike AI frontier promotion (7.3)