PHP获取用户ip、地理位置、浏览器和系统信息

简介: public function service() { $list['ip'] = $_SERVER["REMOTE_ADDR"]; $list['service'] = $this->get_os(); ...
 public function service()
    {
        $list['ip'] = $_SERVER["REMOTE_ADDR"];
        $list['service'] = $this->get_os();
        $list['broswer'] = $this->get_broswer();
        $list['where'] = $this->position($list['ip']);
        dump($list);die;
    }
    /**
     * 获取客户端操作系统信息包括win10
     * @param  null
     * @author  Jea杨
     * @return string
     */
    function get_os(){
        $agent = $_SERVER['HTTP_USER_AGENT'];
        $os = false;

        if (preg_match('/win/i', $agent) && strpos($agent, '95'))
        {
            $os = 'Windows 95';
        }
        else if (preg_match('/win 9x/i', $agent) && strpos($agent, '4.90'))
        {
            $os = 'Windows ME';
        }
        else if (preg_match('/win/i', $agent) && preg_match('/98/i', $agent))
        {
            $os = 'Windows 98';
        }
        else if (preg_match('/win/i', $agent) && preg_match('/nt 6.0/i', $agent))
        {
            $os = 'Windows Vista';
        }
        else if (preg_match('/win/i', $agent) && preg_match('/nt 6.1/i', $agent))
        {
            $os = 'Windows 7';
        }
        else if (preg_match('/win/i', $agent) && preg_match('/nt 6.2/i', $agent))
        {
            $os = 'Windows 8';
        }else if(preg_match('/win/i', $agent) && preg_match('/nt 10.0/i', $agent))
        {
            $os = 'Windows 10';#添加win10判断
        }else if (preg_match('/win/i', $agent) && preg_match('/nt 5.1/i', $agent))
        {
            $os = 'Windows XP';
        }
        else if (preg_match('/win/i', $agent) && preg_match('/nt 5/i', $agent))
        {
            $os = 'Windows 2000';
        }
        else if (preg_match('/win/i', $agent) && preg_match('/nt/i', $agent))
        {
            $os = 'Windows NT';
        }
        else if (preg_match('/win/i', $agent) && preg_match('/32/i', $agent))
        {
            $os = 'Windows 32';
        }
        else if (preg_match('/linux/i', $agent))
        {
            $os = 'Linux';
        }
        else if (preg_match('/unix/i', $agent))
        {
            $os = 'Unix';
        }
        else if (preg_match('/sun/i', $agent) && preg_match('/os/i', $agent))
        {
            $os = 'SunOS';
        }
        else if (preg_match('/ibm/i', $agent) && preg_match('/os/i', $agent))
        {
            $os = 'IBM OS/2';
        }
        else if (preg_match('/Mac/i', $agent) && preg_match('/PC/i', $agent))
        {
            $os = 'Macintosh';
        }
        else if (preg_match('/PowerPC/i', $agent))
        {
            $os = 'PowerPC';
        }
        else if (preg_match('/AIX/i', $agent))
        {
            $os = 'AIX';
        }
        else if (preg_match('/HPUX/i', $agent))
        {
            $os = 'HPUX';
        }
        else if (preg_match('/NetBSD/i', $agent))
        {
            $os = 'NetBSD';
        }
        else if (preg_match('/BSD/i', $agent))
        {
            $os = 'BSD';
        }
        else if (preg_match('/OSF1/i', $agent))
        {
            $os = 'OSF1';
        }
        else if (preg_match('/IRIX/i', $agent))
        {
            $os = 'IRIX';
        }
        else if (preg_match('/FreeBSD/i', $agent))
        {
            $os = 'FreeBSD';
        }
        else if (preg_match('/teleport/i', $agent))
        {
            $os = 'teleport';
        }
        else if (preg_match('/flashget/i', $agent))
        {
            $os = 'flashget';
        }
        else if (preg_match('/webzip/i', $agent))
        {
            $os = 'webzip';
        }
        else if (preg_match('/offline/i', $agent))
        {
            $os = 'offline';
        }
        else
        {
            $os = '未知操作系统';
        }
        return $os;
    }

    /**
     * 获取客户端浏览器信息 添加win10 edge浏览器判断
     * @param  null
     * @author  Jea杨
     * @return string
     */
    function get_broswer(){
        $sys = $_SERVER['HTTP_USER_AGENT'];  //获取用户代理字符串
        if (stripos($sys, "Firefox/") > 0) {
            preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);
            $exp[0] = "Firefox";
            $exp[1] = $b[1];  //获取火狐浏览器的版本号
        } elseif (stripos($sys, "Maxthon") > 0) {
            preg_match("/Maxthon\/([\d\.]+)/", $sys, $aoyou);
            $exp[0] = "傲游";
            $exp[1] = $aoyou[1];
        } elseif (stripos($sys, "MSIE") > 0) {
            preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
            $exp[0] = "IE";
            $exp[1] = $ie[1];  //获取IE的版本号
        } elseif (stripos($sys, "OPR") > 0) {
            preg_match("/OPR\/([\d\.]+)/", $sys, $opera);
            $exp[0] = "Opera";
            $exp[1] = $opera[1];
        } elseif(stripos($sys, "Edge") > 0) {
            //win10 Edge浏览器 添加了chrome内核标记 在判断Chrome之前匹配
            preg_match("/Edge\/([\d\.]+)/", $sys, $Edge);
            $exp[0] = "Edge";
            $exp[1] = $Edge[1];
        } elseif (stripos($sys, "Chrome") > 0) {
            preg_match("/Chrome\/([\d\.]+)/", $sys, $google);
            $exp[0] = "Chrome";
            $exp[1] = $google[1];  //获取google chrome的版本号
        } elseif(stripos($sys,'rv:')>0 && stripos($sys,'Gecko')>0){
            preg_match("/rv:([\d\.]+)/", $sys, $IE);
            $exp[0] = "IE";
            $exp[1] = $IE[1];
        }else {
            $exp[0] = "未知浏览器";
            $exp[1] = "";
        }
        return $exp[0].'('.$exp[1].')';
    }

  function get_position($ip){
    if(empty($ip)){
        return  '缺少用户ip';
     }
     $url = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
     $ipContent = file_get_contents($url);
     $ipContent = json_decode($ipContent,true);
     $list = $ipContent['data']['country'].$ipContent['data']['region'].$ipContent['data']['city'].$ipContent['data']['isp'];
     return $list;
 }
相关文章
|
3月前
|
数据采集 数据安全/隐私保护
Kameleo指纹浏览器进阶使用:轻松集成IPXProxy海外代理IP
Kameleo是一款出色的指纹浏览器,它能够帮助用户实现隐身浏览。大家在进行网络抓取的时候总会碰到一些阻碍,而采取指纹浏览器可以提升网络抓取的效率,并且集成代理IP能增加一层防护,让数据采集更加全面,为制定营销策略提供更好的支持。那如何将Kameleo指纹浏览器与IPXProxy海外代理IP集成?
|
3月前
|
安全 搜索推荐 数据安全/隐私保护
战斧指纹浏览器与IPXProxy海外代理IP的协同使用策略
战斧指纹浏览器是一家专注跨境用户的指纹浏览器,支持IP隔离技术,能够解决账号关联的问题。当然,用户在使用战斧浏览器的时候也可以搭配自有设备,其中IPXProxy的海外代理IP是不错的选择。那战斧指纹浏览器与IPXProxy海外代理IP如何搭配使用?
|
3月前
|
数据安全/隐私保护
YunLogin指纹浏览器与IPXProxy海外代理IP搭配使用的步骤详解
想要运营海外社交媒体账号,需要指纹浏览器和代理IP这两个实用的工具。YunLogin指纹浏览器是不错的选择,用户可以利用指纹浏览器来管理多个社交媒体账号,例如instagram,然后通过给浏览器环境设置不同的代理IP,降低账号关联的风险,确保每个账号都是独立运行。那如何将YunLogin指纹浏览器与IPXProxy海外代理IP搭配使用?
|
3月前
|
安全 iOS开发 MacOS
Dolphin指纹浏览器+IPXProxy代理IP:配置与使用全流程
通过代理IP,用户可以轻松绕过地域限制,访问全球范围内的网站和服务。不过想要同时使用多个代理IP的话,就需要借助指纹浏览器。Dolphin指纹浏览器和IPXProxy代理IP是大家常用的组合,这个组合为用户打造了一个既安全又高效的在线环境。下面是Dolphin指纹浏览器配置IPXProxy代理IP使用步骤,帮助大家更好了解这个组合。
|
3月前
|
安全
全面掌握Dolphin指纹浏览器:IPXProxy代理IP集成使用指南
对于需要管理多个社交媒体或电商平台的用户而言,Dolphin指纹浏览器提供了便捷的多账号隔离功能,搭配代理IP可以有效的防止账户关联。并且Dolphin指纹浏览器能够支持团队协作,方便团队进行互动、跟踪账户、查看代理状态。一些刚接触指纹浏览器的用户,不知道如何将Dolphin指纹浏览器和代理IP集成使用,下面以IPXProxy代理IP为例,带来详细的操作步骤。
|
3月前
|
数据安全/隐私保护
Dolphin指纹浏览器隐私保护升级:IPXProxy代理IP配置实战教程
Dolphin指纹浏览器采用先进的技术,让用户在一台电脑上就可以处理数百个配置文件。每一个配置文件都有着独特的浏览器指纹,极大的保障了用户上网的安全性。并且搭配代理IP一起,还能给每个文件配置不同的IP地址,让网络活动可以畅通无阻。下面给大家带来Dolphin指纹浏览器和IPXProxy代理IP配置详细教程
|
3月前
|
搜索推荐 数据安全/隐私保护
战斧指纹浏览器与IPXProxy海外代理IP配置详解
对于需要管理多个电商平台店铺的用户而言,战斧指纹浏览器提供了便捷的多账号隔离功能。跨境电商卖家要想在海外顺利的管理自己的店铺,还需要用到海外代理IP来实现IP隔离,确保店铺之间互相独立,不会受到其他店铺的牵连。下面以IPXProxy海外代理IP为例,给大家带来战斧指纹浏览器集成IPXProxy海外代理IP的详细指南。
|
3月前
|
数据安全/隐私保护
如何配置战斧指纹浏览器和IPXProxy海外代理IP?
通过代理IP,用户可以轻松绕过地域限制,访问全球范围内的网站和服务。特别是对于跨境用户来说,需要在目标市场投放广告,而代理IP能帮助实现精准投放,快速的提升品牌或者店铺的知名度。那如何在如何在战斧指纹浏览器中设置IPXProxy海外代理IP?
|
3月前
|
数据安全/隐私保护 iOS开发
详细步骤解析:Undetectable指纹浏览器使用IPXProxy代理IP
对于品牌来说,社交媒体已经成为寻找目标受众的丰富资源。在社交媒体平台通过评论和留言进行推广具有很高的转化率,并且推广成本较低。为了获得可观的利润,大家可能需要管理至少几个社交媒体账号,然而在一台电脑上管理多个账号会比较困难。因此使用可靠的工具成为大家的必要选择,其中Undetectable指纹浏览器和IPXProxy代理IP就是两个不错的工具。下面给大家带来Undetectable指纹浏览器配置IPXProxy代理IP的详细教程。
157 0
|
3月前
|
安全
Linken Sphere指纹浏览器中的IPXProxy代理IP设置技巧
大家想要浏览全球资源的时候,往往会遇到很多的阻碍,学会使用指纹浏览器能解决大家不少的烦恼。Linken Sphere指纹浏览器允许配置代理IP,并使用不同的用户代理,不过有些用户不知道该如何进行代理IP的配置。下文就教会大家如何在Linken Sphere指纹浏览器中设置IPXProxy代理IP。
下一篇
无影云桌面