Home  >  Article  >  Backend Development  >  Example of implementation ideas for querying IP location in PHP

Example of implementation ideas for querying IP location in PHP

黄舟
黄舟Original
2017-08-18 15:31:501252browse

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 &#39;ip.php&#39;;//引入类文件
$ip=new iplocation("qqwry.dat");//实例化

$address=$ip->getaddress("183.160.1.86");
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r($address);
?>


Run this file and get the result as shown below:

Example of implementation ideas for querying IP location in PHP

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn