• user_agent


    public function getipinfo($ip) {
    $res = '其他';
    $url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=".$ip;
    $ch = curl_init();
    $SSL = substr($url, 0, 8) == "https://" ? true : false;
    if($SSL)
    {
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_HEADER, 0); // 不要http header 加快效率
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $output = curl_exec($ch);
    curl_close($ch);
    $res1 = preg_match("/({.*})/", $output,$matches);
    if($matches){
    $res2 = json_decode($matches[0], true);
    $res = isset($res2['country'])?($res2['province']?$res2['province']:'其他'):'其他';
    }
    return $res;
    }

    private function check_useragent(){
    $os = $browser = $language = '其他';

    if(strpos($_SERVER["HTTP_USER_AGENT"],"iPhone"))
    $os = "iPhone";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Android"))
    $os = "Android";

    if(strpos($_SERVER["HTTP_USER_AGENT"],"MicroMessenger"))
    $browser = "Wechat";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"MSIE"))
    $browser = "Internet Explorer";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox"))
    $browser = "Firefox";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Chrome"))
    $browser = "Google Chrome";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Safari"))
    $browser = "Safari";
    else if(strpos($_SERVER["HTTP_USER_AGENT"],"Opera"))
    $browser = "Opera";

    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4); //只取前4位,这样只判断最优先的语言。如果取前5位,可能出现en,zh的情况,影响判断。
    if (preg_match("/zh-c/i", $lang))
    $language = "简体中文";
    else if (preg_match("/zh/i", $lang))
    $language = "繁體中文";
    else if (preg_match("/en/i", $lang))
    $language = "English";
    else if (preg_match("/jp/i", $lang))
    $language = "Japanese";
    else if (preg_match("/ko/i", $lang))
    $language = "Korean";
    return array('os'=>$os,'browser'=>$browser,'language'=>$language);
    }

  • 相关阅读:
    vb combobox 用法问题总结
    VB6.0 String 用法总结
    VB6.0 GetTcpTable 使用详解
    Python 自学笔记(二)第一个程序 Hello World
    Python 自学笔记(一)环境搭建
    VB MSFlexGrid 用法
    wifi 攻破
    python核心编程-第五章-习题
    python核心编程-第五章-个人笔记
    python核心编程-第四章-习题
  • 原文地址:https://www.cnblogs.com/echoshao/p/6479128.html
Copyright © 2020-2023  润新知