Home > Article > Backend Development > Example of implementation ideas for querying IP location in PHP
A PHP query ip location code class, the offset address of the first ip index, and the offset address of the last ip index. In order to be compatible with versions below php5, this class does not use a destructor and automatically closes the ip library. The ip is converted into an ipv4 Internet address through ip2long, and then compressed into big-endian byte order, which is used for comparison with the ip address in the index area.
First download the php query IP location code library we need to use for this course: http://www.php.cn/xiazai/leiku/541
Find after the download is complete Unzip the php class file we need to our local directory and create a new php file!
After completion, we need to call this class in the new php file and instantiate the class:
<?php include_once 'ip.php';//引入类文件 $ip=new iplocation("qqwry.dat");//实例化 $address=$ip->getaddress("183.160.1.86"); echo '<pre class="brush:php;toolbar:false">'; print_r($address); ?>
Run this file and get the result as shown below:
The above is the detailed content of Example of implementation ideas for querying IP location in PHP. For more information, please follow other related articles on the PHP Chinese website!