好得很程序员自学网
  • 首页
  • 后端语言
    • 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>

phpiptoarea的简单介绍

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

本文目录一览: 1、 php用IP查询归属地 2、 如何使用php获取本机IP地址 3、 PHP如何获取外网IP地址,类似于百度查询到的IP,网上的方法,查询到的都是局域网(内网)的IP, 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获取本机IP地址

function ip() {

if(getenv('HTTP_CLIENT_IP') strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {

$ip = getenv('HTTP_CLIENT_IP');

} elseif(getenv('HTTP_X_FORWARDED_FOR') strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {

$ip = getenv('HTTP_X_FORWARDED_FOR');

} elseif(getenv('REMOTE_ADDR') strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {

$ip = getenv('REMOTE_ADDR');

} elseif(isset($_SERVER['REMOTE_ADDR']) $_SERVER['REMOTE_ADDR'] strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {

$ip = $_SERVER['REMOTE_ADDR'];

}

return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';

}

以上函数取自phpcms的获取ip方法

PHP如何获取外网IP地址,类似于百度查询到的IP,网上的方法,查询到的都是局域网(内网)的IP,

发一个函数给你.

/**

 * 获取客户端IP地址

 * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字

 * @param boolean $adv 是否进行高级模式获取(有可能被伪装) 

 * @return mixed

 */

function get_client_ip($type = 0,$adv=false) {

    $type       =  $type ? 1 : 0;

    static $ip  =   NULL;

    if ($ip !== NULL) return $ip[$type];

    if($adv){

        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {

            $arr    =   explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);

            $pos    =   array_search('unknown',$arr);

            if(false !== $pos) unset($arr[$pos]);

            $ip     =   trim($arr[0]);

        }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {

            $ip     =   $_SERVER['HTTP_CLIENT_IP'];

        }elseif (isset($_SERVER['REMOTE_ADDR'])) {

            $ip     =   $_SERVER['REMOTE_ADDR'];

        }

    }elseif (isset($_SERVER['REMOTE_ADDR'])) {

        $ip     =   $_SERVER['REMOTE_ADDR'];

    }

    // IP地址合法验证

    $long = sprintf("%u",ip2long($ip));

    $ip   = $long ? array($ip, $long) : array('0.0.0.0', 0);

    return $ip[$type];

}

如果是本地测试的话,获取到的是127.0.0.1

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

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

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

上一篇: php框架路由对比 php框架优缺点

下一篇:php怎么新建画布 php怎么创建

最新资料更新

  • 1.php梗怎么来的 php是什么意思饭圈
  • 2.php网站+iis php网站有哪些
  • 3.php登陆检测 php登录原理
  • 4.php脚本在线解密 php解密网站程序源码
  • 5.php表示数组元素 php数组实现
  • 6.php微信推送提醒 php主动推送消息到安卓
  • 7.php防止ajax接口 php防止接口多次请求
  • 8.bashphp的简单介绍
  • 9.php下面有哪些技术 php运用的技术php开发有哪些实用的技术
  • 10.php7.1des加密 php7 加密
  • 11.phpsql添加记录 php数据表里怎么添加数据
  • 12.php文章发布系统 php发布网站
  • 13.20个php函数 php的system函数
  • 14.订餐系统php 订餐系统升级维护,请前往
  • 15.php多条件动态筛选 php实现数据筛选
  • 16.php分页页数太多 在php中如何对多条记录进行分页
  • 17.php在线做点兼职 php在线做点兼职是真的吗
  • 18.form居中显示php form居中显示
  • 19.php定义多个常量 php定义多个变量
  • 20.搭建分站源码php 建立分站怎么建

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

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