好得很程序员自学网
  • 首页
  • 后端语言
    • C#
    • PHP
    • Python
    • java
    • Golang
    • ASP.NET
  • 前端开发
    • Angular
    • react框架
    • LayUi开发
    • javascript
    • HTML与HTML5
    • CSS与CSS3
    • jQuery
    • Bootstrap
    • NodeJS
    • Vue与小程序技术
    • Photoshop
  • 数据库技术
    • MSSQL
    • MYSQL
    • Redis
    • MongoDB
    • Oracle
    • PostgreSQL
    • Sqlite
    • 数据库基础
    • 数据库排错
  • CMS系统
    • HDHCMS
    • WordPress
    • Dedecms
    • PhpCms
    • 帝国CMS
    • ThinkPHP
    • Discuz
    • ZBlog
    • ECSHOP
  • 高手进阶
    • Android技术
    • 正则表达式
    • 数据结构与算法
  • 系统运维
    • Windows
    • apache
    • 服务器排错
    • 网站安全
    • nginx
    • linux系统
    • MacOS
  • 学习教程
    • 前端脚本教程
    • HTML与CSS 教程
    • 脚本语言教程
    • 数据库教程
    • 应用系统教程
  • 新技术
  • 编程导航
    • 区块链
    • IT资讯
    • 设计灵感
    • 建站资源
    • 开发团队
    • 程序社区
    • 图标图库
    • 图形动效
    • IDE环境
    • 在线工具
    • 调试测试
    • Node开发
    • 游戏框架
    • CSS库
    • Jquery插件
    • Js插件
    • Web框架
    • 移动端框架
    • 模块管理
    • 开发社区
    • 在线课堂
    • 框架类库
    • 项目托管
    • 云服务

当前位置:首页>后端语言>PHP
<tfoot draggable='sEl'></tfoot>

datip库php的简单介绍

很多站长朋友们都不太清楚datip库php,今天小编就来给大家整理datip库php,希望对各位有所帮助,具体内容如下:

本文目录一览: 1、 php用IP查询归属地 2、 关于php的文件dat 3、 php网站 我有ip.dat数据库,如何调取ip.dat并将访客的IP地址、归属地和时间写入.tx php用IP查询归属地

class ip_location

{

function init()

{

$this->wrydat = 'ip_area.dat';

$this->fp = fopen($this->wrydat, 'rb');

$this->getipnumber();

$this->getwryversion();

$this -> REDIRECT_MODE_0 = 0;

$this -> REDIRECT_MODE_1 = 1;

$this -> REDIRECT_MODE_2 = 2;

}

function get($str)

{

return $this->$str;

}

function set($str,$val)

{

$this->$str = $val;

}

function getbyte($length,$offset=null)

{

!is_null($offset) fseek($this->fp, $offset, SEEK_SET);

return fread($this->fp, $length);

}

function packip($ip)

{

return pack('N', intval(ip2long($ip)));

}

function getlong($length=4, $offset=null)

{

$chr=null;

for($c=0;$length%4!=0$c<(4-$length%4);$c++)

{

$chr .= chr(0);

}

$var = unpack( 'Vlong', $this->getbyte($length, $offset).$chr);

return $var['long'];

}

function getwryversion()

{

$length = preg_match("/coral/i",$this->wrydat)?26:30;

$this->wrydat_version = $this->getbyte($length, $this->firstip-$length);

}

function getipnumber()

{

$this->firstip = $this->getlong();

$this->lastip = $this->getlong();

$this->ipnumber = ($this->lastip-$this->firstip)/7+1;

}

function getstring($data='', $offset=NULL)

{

$char = $this->getbyte(1,$offset);

while(ord($char) > 0)

{

$data .= $char;

$char = $this->getbyte(1);

}

return $data;

}

function iplocaltion($ip)

{

$ip = $this->packip($ip);

$low = 0;

$high = $this->ipnumber-1;

$ipposition = $this->lastip;

while($low <= $high)

{

$t = floor(($low+$high)/2);

if($ip < strrev($this->getbyte(4,$this->firstip+$t*7)))

$high = $t - 1;

else

{

if($ip > strrev($this->getbyte(4,$this->getlong(3))))

$low = $t + 1;

else

{

$ipposition = $this->firstip+$t*7;

break;

}

}

}

return $ipposition;

}

function getarea()

{

$b = $this->getbyte(1);

switch(ord($b))

{

case $this -> REDIRECT_MODE_0 :

return '';

break;

case $this -> REDIRECT_MODE_1:

case $this -> REDIRECT_MODE_2:

return $this->getstring('',$this->getlong(3));

break;

default:

return $this->getstring($b);

break;

}

}

function getiplocation($ip)

{

$ippos = $this->iplocaltion($ip);

$this->ip_range_begin = long2ip($this->getlong(4,$ippos));

$this->ip_range_end = long2ip($this->getlong(4,$this->getlong(3)));

$b = $this->getbyte(1);

switch(ord($b))

{

case $this -> REDIRECT_MODE_1:

$b = $this->getbyte(1,$this->getlong(3));

if(ord($b) == $this -> REDIRECT_MODE_2)

{

$countryoffset = $this->getlong(3);

$this->area = $this->getarea();

$this->country = $this->getstring('',$countryoffset);

}

else

{

$this->country = $this->getstring($b);

$this->area = $this->getarea();

}

break;

case $this -> REDIRECT_MODE_2:

$countryoffset = $this->getlong(3);

$this->area = $this->getarea();

$this->country = $this->getstring('',$countryoffset);

break;

default:

$this->country = $this->getstring($b);

$this->area = $this->getarea();

break;

}

}

}

---------------------------------------------------------------

调用方法:

$iploca = new ip_location;

$iploca -> init();

$iploca -> getiplocation($ip);

$area['country'] = str_replace(array('CZ88.NET'), '', $iploca -> get('country'));

$area['area'] = str_replace(array('CZ88.NET'), '', $iploca -> get('area'));

$area['country']=='' $area['country']='未知';

$area['area']=='' $area['area']='未知';

return $area;

关于php的文件dat

这个是自己构造的一个存储文件,要看源码了解存储格式后,才能按照源码规定的格式写入数据。源码不长的话放出来看看。

补充:

搜了下你说的数据库,如果你说的数据库是名人名言数据库,其数据结构很简单。每条记录包括人名和名言,以行为单位存放,人名和名言之间用制表符隔开。

写入时可以这样:

$name="人名";

$note="名言";

$fp=fopen('myan.dat','a');

fwrite($fp,"$name\t$note\r\n");

fclose($fp);

php网站 我有ip.dat数据库,如何调取ip.dat并将访客的IP地址、归属地和时间写入.tx

PHP可以获取到访客的IP,然后查询归属地,这个网上很多接口有提供

关于datip库php的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。

查看更多关于datip库php的简单介绍的详细内容...

声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did195063
更新时间:2023-04-26   阅读:28次

上一篇: php图片文件上传 php上传图片并显示图片代码

下一篇:php文字上下翻动 php怎么让文字居中

相关资讯

最新资料更新

  • 1.php读取pdf内容 php读取文本文件
  • 2.php5.2cgi的简单介绍
  • 3.php梗怎么来的 php是什么意思饭圈
  • 4.php每个小时执行 php定时执行每天执行一次
  • 5.php常量乱码 phpstorm乱码
  • 6.phpmysql框架 php框架yii
  • 7.php数据导出csv php导出大量数据
  • 8.关于php2esgbi的信息
  • 9.php棋牌小游戏 棋牌类小程序
  • 10.linux中下载php linux安装php56
  • 11.php用户检索记录系统 php搜索数据库
  • 12.php内核源码剖析 php源码使用教程
  • 13.php部署云空间 php云开发
  • 14.php开发宝典 php7开发宝典pdf下载
  • 15.phpword读写 php读写word 文档
  • 16.php_syntax的简单介绍
  • 17.php数据层设计 php数据库操作
  • 18.php时间戳转换字符串 php 时间戳转日期
  • 19.phppngjpeg的简单介绍
  • 20.关于PHPchmod的信息

CopyRight:2016-2025好得很程序员自学网 备案ICP:湘ICP备09009000号-16 http://haodehen.cn
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2025 「好得很程序员自学网」
[ SiteMap ]