zoukankan      html  css  js  c++  java
  • 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);
    }

  • 相关阅读:
    dll-IL-metadata-反射
    Linux(Ubuntu)下安装Angular2
    在nodejs中使用input file批量上传文件的方法
    jq动态添加的元素触发绑定事件无效
    简单的在线计算器
    不同方法实现按钮背景图片的变换
    unity特殊文件夹
    《暗黑战神》随堂笔记
    《打砖块》教程知识梳理
    unity零散小知识
  • 原文地址:https://www.cnblogs.com/echoshao/p/6479128.html
Copyright © 2011-2022 走看看