ThinkPHP中IP地址定位,包括IP地址库资料

WBOY
Release: 2016-06-13 13:11:01
Original
830 people have browsed it

ThinkPHP中IP地址定位,包括IP地址库文件

前几天,研究了一下TP中IP地址定位,着实费了一些时间,现在解决了,分享给大家。
IP地址库有点大,去这里下载http://download.csdn.net/detail/man_quan/4636418
用于IP地址的定位,解压后的类库文件放入ThinkPHP/Extend/Library/ORG/Net(如果不存在请手动创建)目录下面
然后使用import方法引入后操作
  1. import('ORG.Net.IpLocation');// 导入IpLocation类
  2. $Ip = new IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件
  3. $area = $Ip->getlocation('203.34.5.66'); // 获取某个IP地址所在的位置
如果传入的参数为空,则会自动获取当前的客户端IP地址,要正确输出位置,必须配合UTF8编码的ip地址库文件,否则可能还需要进行编码转换。IP地址库文件和IpLocation类库位于同一目录即可。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!